From 8a9c2f66fd6721937e97f0f875cdd16af01d79c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=A2=E7=BF=8A=E5=87=A1?= Date: Mon, 24 Aug 2026 18:21:25 +0800 Subject: [PATCH] Guard deprecated astype copy keyword by pandas version in encode_values_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 --- DataSynthesizer/datatypes/DateTimeAttribute.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/DataSynthesizer/datatypes/DateTimeAttribute.py b/DataSynthesizer/datatypes/DateTimeAttribute.py index 3d425fa..1b05bc1 100644 --- a/DataSynthesizer/datatypes/DateTimeAttribute.py +++ b/DataSynthesizer/datatypes/DateTimeAttribute.py @@ -2,8 +2,12 @@ from typing import Union import numpy as np +import pandas as pd from dateutil.parser import parse from pandas import Series, concat +from packaging.version import Version + +PANDAS_VERSION = Version(pd.__version__) from DataSynthesizer.datatypes.AbstractAttribute import AbstractAttribute from DataSynthesizer.datatypes.utils.DataType import DataType @@ -75,7 +79,10 @@ def encode_values_into_bin_idx(self): encoded = concat([encoded, self.data], axis=1).iloc[:, 0] encoded.fillna(len(self.distribution_bins), inplace=True) - return encoded.astype(int, copy=False) + if PANDAS_VERSION < Version("3.0"): + return encoded.astype(int, copy=False) + else: + return encoded.astype(int) def generate_values_as_candidate_key(self, n): return np.arange(self.min, self.max, (self.min - self.max) / n)