Commit c3e653b
authored
Fixes #1768
# Description
Fixes broken pieces of the code when updating to pandas 3, which [has
the following major
changes](https://pandas.pydata.org/community/blog/pandas-3.0.html) which
also affect iMOD Python somewhat:
- _Dedicated string data type by default: string columns are now
inferred as the new str dtype instead of object, providing better
performance and type safety_
- _Consistent copy/view behaviour with Copy-on-Write (CoW) (a.k.a.
getting rid of the SettingWithCopyWarning): more predictable and
consistent behavior for all operations, with improved performance
through avoiding unnecessary copies_
- _New default resolution for datetime-like data: no longer defaulting
to nanoseconds, but generally microseconds (or the resolution of the
input), when constructing datetime or timedelta data (avoiding
out-of-bounds errors for dates with a year before 1678 or after 2262)_
Because of these changes, some parts of the code had to be modified
slightly to get the tests to work. I think with the latter change we
could simplify the code base a lot, as all logic to deal with datetimes
going beyond the year 2262 and prior to 1678 wouldn't be necessary
anymore. This was quite a headache in the past, and I think the choice
for microseconds by default will make our lives significantly easier. [I
created an issue for
this](#1773).
In detail this PR alters the following:
- Pin pandas version to 3.* in pixi.toml
- Update setup and asserts in quite some tests to work with pandas 3.0.
Most of these tests will not work with pandas 2.0 anymore, as we now
assert for pandas 3.0 behavior
- Update examples to work with pandas 3.0
- Fix statements where a view was altered (e.g. altering ``.values``
attribute), this is now forbidden by pandas
- Update to new string handling, sometimes I had to internally enforce
object dtype to get the old behavior. In other cases we could check for
strings by checking ``dtype=="object"`` anymore. Luckily there is
``pd.api.types.is_string_dtype``, which both works for pandas 2 as well
as pandas 3.
- Add unittest for ``to_pandas_datetime_series`` to check whether pandas
behavior is similar in this regard.
# Checklist
<!---
Before requesting review, please go through this checklist:
-->
- [x] Links to correct issue
- [x] Update changelog, if changes affect users
- [x] PR title starts with ``Issue #nr``, e.g. ``Issue #737``
- [x] Unit tests were added
- [ ] **If feature added**: Added/extended example
- [ ] **If feature added**: Added feature to API documentation
- [ ] **If pixi.lock was changed**: Ran `pixi run generate-sbom` and
committed changes
1 parent eb64237 commit c3e653b
File tree
28 files changed
+299
-236
lines changed- docs/api
- examples
- imod-wq
- mf6
- imod
- evaluate
- formats
- gen
- mf6/multimodel
- tests
- test_evaluate
- test_formats
- test_mf6
- test_typing
- test_util
- test_wq
- util
28 files changed
+299
-236
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| 47 | + | |
| 48 | + | |
47 | 49 | | |
48 | 50 | | |
49 | 51 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
105 | | - | |
| 105 | + | |
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
194 | 194 | | |
195 | 195 | | |
196 | 196 | | |
197 | | - | |
| 197 | + | |
198 | 198 | | |
199 | 199 | | |
200 | 200 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
336 | 336 | | |
337 | 337 | | |
338 | 338 | | |
339 | | - | |
| 339 | + | |
340 | 340 | | |
341 | 341 | | |
342 | 342 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
129 | | - | |
| 129 | + | |
| 130 | + | |
130 | 131 | | |
131 | 132 | | |
132 | 133 | | |
| |||
254 | 255 | | |
255 | 256 | | |
256 | 257 | | |
257 | | - | |
258 | | - | |
259 | | - | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
260 | 263 | | |
261 | 264 | | |
262 | 265 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
267 | 267 | | |
268 | 268 | | |
269 | 269 | | |
270 | | - | |
| 270 | + | |
271 | 271 | | |
272 | 272 | | |
273 | 273 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
458 | 458 | | |
459 | 459 | | |
460 | 460 | | |
461 | | - | |
| 461 | + | |
| 462 | + | |
462 | 463 | | |
463 | 464 | | |
464 | 465 | | |
| |||
509 | 510 | | |
510 | 511 | | |
511 | 512 | | |
512 | | - | |
| 513 | + | |
| 514 | + | |
513 | 515 | | |
514 | 516 | | |
515 | 517 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
290 | 290 | | |
291 | 291 | | |
292 | 292 | | |
293 | | - | |
294 | | - | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
295 | 296 | | |
296 | | - | |
297 | | - | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
298 | 300 | | |
299 | 301 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
| 97 | + | |
| 98 | + | |
102 | 99 | | |
103 | 100 | | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
| |||
0 commit comments