Skip to content

pd.concat(..., copy=False) in smtrain.py emits Pandas4Warning on pandas ≥3.0 — drop the deprecated copy keyword #375

Description

@xyf5432

Summary

src/ceasiompy/smtrain/smtrain.py calls pd.concat(..., copy=False),
which is deprecated in pandas 3.0:

File Line
src/ceasiompy/smtrain/smtrain.py 335 pd.concat([level1_df, level2_df], ignore_index=True, copy=False)

Verified on pandas 3.0.5:

>>> pd.concat([df1, df2], ignore_index=True, copy=False)
Pandas4Warning: The copy keyword is deprecated and will be removed in a
future version. Copy-on-Write is active in pandas since 3.0 which utilizes
a lazy copy mechanism that defers copies until necessary. Use .copy() to
make an eager copy if necessary.

Pandas4Warning is a DeprecationWarning subclass, so it is invisible
by default and does not fail CI — but it fires whenever the
two-fidelity surrogate-model training reaches the final results
concatenation under pandas ≥3.0, and the keyword will be removed in a
future version.

Suggested fix: version-guarded branch

Guard the call on the pandas version — keep copy=False on pandas <3.0
(where it still skips copying intermediate data) and drop it on ≥3.0,
following the pattern used in NVIDIA/cuml#8142:

if PANDAS_VERSION < Version("3.0"):
    pd.concat([level1_df, level2_df], ignore_index=True, copy=False)
else:
    pd.concat([level1_df, level2_df], ignore_index=True)

with PANDAS_VERSION = Version(pd.__version__) at module level
(packaging is already a transitive dependency of pandas).

This is behaviour-preserving on every pandas version: the copy
keyword never affects the result of concat, only whether input
buffers are copied, and the branch keeps that behaviour exactly as it
was on each side of the boundary. Verified with runtime checks in
isolated venvs:

  • pandas 2.3.3 takes the copy=False branch: identical results to
    today's code (ignore_index=True row append), no warning.
  • pandas 3.0.5 takes the plain branch: no Pandas4Warning is emitted,
    results identical (the copy keyword is a documented no-op under
    Copy-on-Write).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions