Skip to content

Add Support for Pandas 3 #3380

Description

@leowerneck

Description

The pandas<3 constraint added in #3334 avoids test failures under pandas 3, but the incompatibilities can be addressed directly. The goal of this issue is to support both pandas 2.x and 3.x without version checks or changes to global pandas options.

The most visible failures come from pandas 3 Copy-on-Write behavior. NumPy arrays returned by Series.to_numpy() may be read-only, so tests that mutate them fail with:

ValueError: assignment destination is read-only

A full test run also exposes pandas 3 string-extension-array behavior in CDF serialization, mixed-type xarray filtering, IDEX trigger-mode handling, and a few tests that mutate index-backed arrays.

Reproduction

Install the repository with pandas 3.0.5 and run:

poetry run pytest -n auto

With the otherwise unchanged test environment, pandas 2.2.3 passes the suite, while pandas 3.0.5 produces 25 failures. The focused SWAPI failures can be reproduced with:

python -m pytest \
  imap_processing/tests/ialirt/unit/test_process_swapi.py \
  -m "not external_test_data and not external_kernel" \
  -q --tb=short

Affected areas and suggested fixes

  • Use to_numpy(copy=True) where returned arrays are intentionally mutated, including the SWAPI optimization tests.
  • Convert pandas extension arrays to NumPy-backed arrays at the CDF-writing boundary without modifying the source dataset.
  • Avoid mixed-type pandas Series assignment when parsing Excel state tables.
  • Use direct xarray indexing when filtering and dropping complete records from mixed-type datasets.
  • Preserve None explicitly in IDEX trigger-mode object arrays.
  • Return copied NumPy data from the Ultra energy lookup.
  • Make dimensions and writable-copy requirements explicit in affected tests.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

Status
PR Open

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions