Commit f1c16c0
authored
Don't copy dataframes or use inplace=True (#305)
Pandas is moving away from the `inplace=True` argument in its next
version, and recommends against using it as most methods make copies of
the underlying data anyway, and using inplace is more likely to lead to
bugs:
pandas-dev/pandas#16529
pandas-dev/pandas#51466
We also have a lot of code that looks like:
```python
df = table.dataframe.copy()
df.foobar(..., inplace=True)
...
table = replace(table, dataframe=df)
```
which is better written as the following, as most pandas methods
`foobar` return a new dataframe with the results of the operation:
```python
df = table.dataframe.foobar(...)
...
table = replace(table, dataframe=df)
```
It is not necessary to copy dataframes unless in very special cases, for
example, you are adding a column to the dataframe:
```python
df = model.topology.copy() # This copy is needed, otherwise the next line adds a column to `model.topology`
df['new_col'] = df['old_col'] * 2
```1 parent bbb9afc commit f1c16c0
File tree
5 files changed
+107
-125
lines changed- xl2times
5 files changed
+107
-125
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
313 | 313 | | |
314 | 314 | | |
315 | 315 | | |
316 | | - | |
317 | | - | |
| 316 | + | |
318 | 317 | | |
319 | 318 | | |
320 | 319 | | |
| |||
326 | 325 | | |
327 | 326 | | |
328 | 327 | | |
329 | | - | |
| 328 | + | |
330 | 329 | | |
331 | 330 | | |
332 | 331 | | |
| |||
352 | 351 | | |
353 | 352 | | |
354 | 353 | | |
355 | | - | |
| 354 | + | |
356 | 355 | | |
357 | 356 | | |
358 | 357 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
295 | 295 | | |
296 | 296 | | |
297 | 297 | | |
298 | | - | |
299 | | - | |
| 298 | + | |
| 299 | + | |
300 | 300 | | |
301 | 301 | | |
302 | 302 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
170 | 170 | | |
171 | 171 | | |
172 | 172 | | |
173 | | - | |
| 173 | + | |
174 | 174 | | |
175 | 175 | | |
176 | 176 | | |
| |||
0 commit comments