Avoid deprecated inplace keyword in DataFrame.rename (#225)

Closes #225 (closed)

Summary

pandas 3.1 deprecates the inplace keyword of DataFrame.rename (PDEP-8) and raises a Pandas4Warning. CoSApp used this keyword in two places, both to apply natural_varname to column names:

  • SystemSurrogate.filter_headers (cosapp/systems/systemSurrogate.py)
  • BatchRunner.filter_headers (cosapp/systems/batch.py)

Both methods now rename columns by assigning DataFrame.columns directly. Their signatures and their in-place behaviour are unchanged.

Bug fix

BatchRunner.filter_headers(df, inplace=False) used to throw away the renamed copy and return the original dataframe with its columns unchanged. It now returns a renamed copy and leaves the input dataframe untouched.

Tests

  • New tests for both filter_headers methods check column renaming and in-place vs. copy behaviour, and fail if any warning is raised.
  • The new inplace=False test fails on the previous implementation.
  • pytest cosapp/systems passes on Python 3.12 and 3.13 (521 passed, 17 skipped).

Notes for reviewers

  • The test environments use pandas 3.0.6, which does not have this deprecation yet. The tests check that no warning is raised, but it still needs a check with pandas >= 3.1 that the Pandas4Warning is gone.

Merge request reports

Loading
Loading