Skip to content

Guard deprecated astype copy keyword by pandas version in encode_values_into_bin_idx - #48

Open
xyf5432 wants to merge 1 commit into
DataResponsibly:masterfrom
xyf5432:fix/pandas3-astype-copy-deprecation
Open

Guard deprecated astype copy keyword by pandas version in encode_values_into_bin_idx#48
xyf5432 wants to merge 1 commit into
DataResponsibly:masterfrom
xyf5432:fix/pandas3-astype-copy-deprecation

Conversation

@xyf5432

@xyf5432 xyf5432 commented Aug 24, 2026

Copy link
Copy Markdown

PR: Guard deprecated astype copy keyword by pandas version in encode_values_into_bin_idx

Fixes #47

Changes

Guard the deprecated copy keyword of Series.astype by pandas
version in DateTimeAttribute.encode_values_into_bin_idx, so behaviour
is preserved on every supported version:

  • DataSynthesizer/datatypes/DateTimeAttribute.py: module-level
    PANDAS_VERSION = Version(pd.__version__) (from packaging, already
    a transitive dependency of pandas), and

    if PANDAS_VERSION < Version("3.0"):
        return encoded.astype(int, copy=False)
    else:
        return encoded.astype(int)

    — the same pattern as Fix pandas 3 string dtype compatibility and CI flakes NVIDIA/cuml#8142.

Verification

The copy keyword never affects the result of astype on any
pandas version, only whether an extra copy is made; the branch keeps
that behaviour exactly as it was on each side of the boundary. Runtime
checks on pandas 2.3.3 and 3.0.5 (Series → fillna → branch):

  • pandas 2.3.3 takes the copy=False branch, results identical.
  • 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).
  • The modified file passes python -m py_compile.

…es_into_bin_idx

The copy keyword of Series.astype is deprecated in pandas 3.0
(Pandas4Warning). Pass it only on pandas <3.0, where it still avoids an
extra copy when the dtype is unchanged; omit it on >=3.0 where it is a
documented no-op under Copy-on-Write.

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

astype(..., copy=False) in encode_values_into_bin_idx emits Pandas4Warning on pandas ≥3.0 — drop the deprecated copy keyword

1 participant