Added Pandas 3 Support - #3382
Conversation
…py(copy=True) when array is mutated, supporting Pandas 3
| accumulated_data["met"] = met | ||
|
|
||
| # Drop any off-nominal SWE groups | ||
| nominal_data = accumulated_data.where( |
There was a problem hiding this comment.
It is concerning to me that upgrading to pandas 3 breaks xarray DataArray.where functionality. This fix seems like a hack to avoid some underlying issue.
There was a problem hiding this comment.
The issue isn't DataArray.where() specifically, but DataArray.where(..., drop=True). Numeric DataArray.where() calls still work and were preserved, but when the intent is "keep records whose epoch satifies this condition", then:
dataset.where(condition, drop=True)was replaced with:
dataset.isel(epoch=condition.values)Using isel here avoids e.g., unnecessary fill-value computation.
There was a problem hiding this comment.
Using isel here avoids e.g., unnecessary fill-value computation.
Very good point.
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def _cdf_compatible_dataset(dataset: xr.Dataset) -> xr.Dataset: |
There was a problem hiding this comment.
@bryan-harter is the author of cdflib. It feels to me like this should be a ticket for adding pandas 3 support to cdflib.
There was a problem hiding this comment.
Pull request overview
Broadens pandas 3 compatibility across data processing, serialization, and tests.
Changes:
- Copies arrays before mutation and uses NumPy-backed lookups.
- Adds explicit xarray dimensions and positional filtering.
- Normalizes pandas extension arrays and inferred string/state values.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
imap_processing/ultra/l1b/lookup_utils.py |
Uses integer NumPy indexing for energy lookup. |
imap_processing/tests/ultra/unit/test_ultra_l1b_culling.py |
Adds explicit test dimensions. |
imap_processing/tests/swapi/test_swapi_l1.py |
Adds explicit epoch dimensions. |
imap_processing/tests/mag/test_mag_l2.py |
Copies mutable expected epoch data. |
imap_processing/tests/ialirt/unit/test_process_swapi.py |
Copies arrays before mutation. |
imap_processing/tests/cdf/test_utils.py |
Tests extension-array conversion. |
imap_processing/idex/idex_l1b.py |
Preserves object-backed trigger modes. |
imap_processing/ialirt/utils/grouping.py |
Uses positional boolean filtering. |
imap_processing/ialirt/l0/process_swe.py |
Uses positional filtering for SWE data. |
imap_processing/cdf/utils.py |
Converts extension arrays before CDF serialization. |
imap_processing/ccsds/excel_to_xtce.py |
Converts state rows to plain mappings. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Change Summary
Closes #3380.
Overview
Add support for both pandas 2.x and pandas 3.x. The changes account for pandas 3's copy-on-write behavior and default string extension arrays while preserving the behavior of existing processing code under pandas 2.2.3.
The compatibility updates include:
Nonevalues in IDEX trigger-mode object arrays.These changes do not use pandas-version checks or alter global pandas options.
File changes
imap_processing/ccsds/excel_to_xtce.pyimap_processing/cdf/utils.pycdflib.imap_processing/ialirt/l0/process_swe.pyisel()operations when filtering complete records from a mixed-type Dataset. This avoids asking xarray to create fill values for pandas string extension arrays when the rejected records are immediately dropped.imap_processing/ialirt/utils/grouping.pyimap_processing/idex/idex_l1b.pyNonerather than being inferred as string missing values/NaN.imap_processing/ultra/l1b/lookup_utils.pyimap_processing/tests/ialirt/unit/test_process_swapi.pyto_numpy(copy=True)in five places where the returned arrays are subsequently mutated.imap_processing/tests/cdf/test_utils.pycdflibwithout mutating the source Dataset.imap_processing/tests/mag/test_mag_l2.pyimap_processing/tests/swapi/test_swapi_l1.pyepochdimension explicitly for mutable test variables.imap_processing/tests/ultra/unit/test_ultra_l1b_culling.pyspin,energy_bin, andenergy_edgedimensions explicitly so mutable test variables are not implicitly constructed as index coordinates.Testing
Two clean Poetry environments were exercised with the test and development extras. The dependency set was held constant apart from the pandas version (Python 3.12, NumPy 2.2.6, and xarray 2025.4.0).
Baseline results before the compatibility fixes:
Post-fix full-suite results from: