Conditions | 4 |
Total Lines | 66 |
Code Lines | 10 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | from datetime import datetime |
||
141 | def add_data(self) -> None: |
||
142 | with self.database.engine.begin() as connection: |
||
143 | queries = [ |
||
144 | """ |
||
145 | insert ignore into companies ( |
||
146 | code_uic, |
||
147 | short_name, |
||
148 | name, |
||
149 | country_code_iso, |
||
150 | allocation_date, |
||
151 | modified_date, |
||
152 | begin_of_validity, |
||
153 | end_of_validity, |
||
154 | freight, |
||
155 | passenger, |
||
156 | infrastructure, |
||
157 | holding, |
||
158 | integrated, |
||
159 | other, |
||
160 | url |
||
161 | ) |
||
162 | values ( |
||
163 | :code_uic, |
||
164 | :short_name, |
||
165 | :name, |
||
166 | :country_code_iso, |
||
167 | :allocation_date, |
||
168 | :modified_date, |
||
169 | :begin_of_validity, |
||
170 | :end_of_validity, |
||
171 | :freight, |
||
172 | :passenger, |
||
173 | :infrastructure, |
||
174 | :holding, |
||
175 | :integrated, |
||
176 | :other, |
||
177 | :url |
||
178 | ) |
||
179 | """, |
||
180 | """ |
||
181 | update companies |
||
182 | set |
||
183 | short_name = :short_name, |
||
184 | name = :name, |
||
185 | country_code_iso = :country_code_iso, |
||
186 | allocation_date = :allocation_date, |
||
187 | modified_date = :modified_date, |
||
188 | begin_of_validity = :begin_of_validity, |
||
189 | end_of_validity = :end_of_validity, |
||
190 | freight = :freight, |
||
191 | passenger = :passenger, |
||
192 | infrastructure = :infrastructure, |
||
193 | holding = :holding, |
||
194 | integrated = :integrated, |
||
195 | other = :other, |
||
196 | url = :url |
||
197 | where |
||
198 | code_uic = :code_uic |
||
199 | """, |
||
200 | ] |
||
201 | |||
202 | for index, row in self.data.iterrows(): |
||
203 | for query in queries: |
||
204 | connection.execute( |
||
205 | text(query), |
||
206 | row.to_dict(), |
||
207 | ) |
||
208 |