Commit f621591
authored
Add pandas 3.0 support (#294)
* Fix pandas 3.0 incompatibilities in GEO, BEYONDCOAL and MASTR loaders
- clean_name: astype(str) preserves NA under the pandas 3 string dtype,
so unidecode received float NaN for unnamed plants (GEO, reduced
retrieval). fillna("") before the conversion.
- BEYONDCOAL: the future.no_silent_downcasting option was removed in
pandas 3 (its behaviour is now the default); requesting it raises.
Guard the option_context behind a version check.
- MASTR: the chunked low-memory parser crashes with usecols on
pandas 3 (IndexError in the DtypeWarning column lookup); read with
low_memory=False. Postleitzahl astype(str) preserves NA, breaking the
final astype(int); fillna("0") in between, identical outcome on
pandas 2 where NaN already became the string "nan" -> "000".
All previously failing non-Duke tests pass under pandas 3.0.3
(test_data, test_plots, test_aggregate[GEO/BEYONDCOAL/MASTR],
test_reduced_retrieval); behaviour unchanged under pandas 2.x.
* Complete pandas 3.0 support: lift pin to <4, fix Duke/aggregate/matching paths
Relax the dependency pin from pandas<3 to pandas<4 and fix the four
remaining breakages that surface once pandas 3 is installed (these sit
behind the Java-gated Duke aggregate/matching tests, so they are not
visible without a JDK on PATH):
- duke.add_geoposition_for_duke: astype(str) preserves NA on pandas 3,
so ','.join hit a float NaN. Stringify per item (map(str, s)) so NaN
becomes 'nan', keeping the 'nan,nan' -> NaN cleanup valid.
- cleaning.aggregate_units: second future.no_silent_downcasting
option_context (the twin of the BEYONDCOAL one) version-gated; drop
the deprecated copy= kwarg from infer_objects (no-op under CoW).
- matching.best_matches: groupby(...).apply with as_index=False
re-inserts the grouping column on pandas 3, absent from the per-group
Series -> KeyError. Rewrote with a vectorised idxmax (behaviour-
identical, faster, no apply).
Full test suite (incl. Duke aggregate + matching) passes under both
pandas 2.x and 3.0.3.
* Remove inline review comments from pandas 3 fixes
Per maintainer review on #294: drop the explanatory comments added for
review. Code changes are unchanged.
* Extract pandas-3 check into PANDAS_V3 constant
Addresses the review on #294: replace the inline
parse_version(pd.__version__).major < 3 check with a named PANDAS_V3
constant defined once in core.py, used by both cleaning.aggregate_units
and data.BEYONDCOAL. Behaviour unchanged; full test suite passes (48)
under pandas 3.0.3.1 parent 459f19f commit f621591
6 files changed
Lines changed: 35 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
17 | | - | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
74 | 75 | | |
75 | 76 | | |
76 | 77 | | |
77 | | - | |
| 78 | + | |
78 | 79 | | |
79 | 80 | | |
80 | 81 | | |
| |||
513 | 514 | | |
514 | 515 | | |
515 | 516 | | |
516 | | - | |
517 | | - | |
518 | | - | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
519 | 524 | | |
520 | 525 | | |
521 | 526 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
9 | 16 | | |
10 | 17 | | |
11 | 18 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
27 | | - | |
| 28 | + | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| |||
93 | 94 | | |
94 | 95 | | |
95 | 96 | | |
96 | | - | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
97 | 103 | | |
98 | 104 | | |
99 | 105 | | |
| |||
2398 | 2404 | | |
2399 | 2405 | | |
2400 | 2406 | | |
2401 | | - | |
| 2407 | + | |
2402 | 2408 | | |
2403 | 2409 | | |
2404 | 2410 | | |
| |||
2434 | 2440 | | |
2435 | 2441 | | |
2436 | 2442 | | |
2437 | | - | |
| 2443 | + | |
| 2444 | + | |
| 2445 | + | |
| 2446 | + | |
2438 | 2447 | | |
2439 | 2448 | | |
2440 | 2449 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
29 | | - | |
| 28 | + | |
30 | 29 | | |
31 | 30 | | |
32 | 31 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
38 | | - | |
39 | | - | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| |||
0 commit comments