Skip to content

Commit 9aed894

Browse files
authored
Update pandas version upper bound to support python 3.14 (#39056)
* Update pandas version upper bound to support python 3.14 * Fix the failed tests causing by updating pandas * Skip the test as the pandas bug is unfixed at 2.3.3 * Refactor get_dummies NaN column lookup to use global static constant
1 parent 54231e8 commit 9aed894

3 files changed

Lines changed: 12 additions & 5 deletions

File tree

sdks/python/apache_beam/dataframe/frames.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@
6363
# Get major, minor version
6464
PD_VERSION = tuple(map(int, pd.__version__.split('.')[0:2]))
6565

66+
# Find the name pandas uses for the NaN column in get_dummies().
67+
# Older pandas versions (<2.3.0) use 'nan', whereas newer versions (>=2.3.0) use 'NaN'.
68+
_DUMMY_NAN_COLUMN = 'NaN' if PD_VERSION >= (2, 3) else 'nan'
69+
6670

6771
def populate_not_implemented(pd_type):
6872
def wrapper(deferred_type):
@@ -5054,7 +5058,8 @@ def get_dummies(self, **kwargs):
50545058
# the data includes NaNs, which is not valid to be casted as a Category,
50555059
# but nevertheless would be broadcasted as a column in get_dummies()
50565060
columns = sorted(set().union(*split_cats))
5057-
columns = columns + ['nan'] if 'nan' not in columns else columns
5061+
if _DUMMY_NAN_COLUMN not in columns:
5062+
columns = columns + [_DUMMY_NAN_COLUMN]
50585063

50595064
proxy = pd.DataFrame(columns=columns).astype(int)
50605065

sdks/python/apache_beam/dataframe/frames_test.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737

3838
# Get major, minor version
3939
PD_VERSION = tuple(map(int, pd.__version__.split('.')[0:2]))
40+
# Get major, minor, patch version
41+
PD_FULL_VERSION = tuple(int(x) for x in re.findall(r'\d+', pd.__version__)[0:3])
4042

4143
GROUPBY_DF = pd.DataFrame({
4244
'group': ['a' if i % 5 == 0 or i % 3 == 0 else 'b' for i in range(100)],
@@ -1437,7 +1439,7 @@ def test_unstack_pandas_example2(self):
14371439
self._run_test(lambda s: s.unstack(level=0), s)
14381440

14391441
@unittest.skipIf(
1440-
sys.version_info >= (3, 12) and PD_VERSION < (2, 3),
1442+
sys.version_info >= (3, 12) and PD_FULL_VERSION < (2, 3, 4),
14411443
'https://github.com/pandas-dev/pandas/issues/58604')
14421444
def test_unstack_pandas_example3(self):
14431445
index = self._unstack_get_categorical_index()

sdks/python/setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def cythonize(*args, **kwargs):
162162
# https://github.com/pandas-dev/pandas/issues/45725
163163
# must update the below "docs" and "test" for extras_require
164164
dataframe_dependency = [
165-
'pandas>=1.4.3,!=1.5.0,!=1.5.1,<2.3',
165+
'pandas>=1.4.3,!=1.5.0,!=1.5.1,<2.4',
166166
]
167167

168168
milvus_dependency = ['pymilvus>=2.5.10,<3.0.0']
@@ -485,7 +485,7 @@ def get_portability_package_data():
485485
'docstring-parser>=0.15,<1.0',
486486
'docutils>=0.18.1',
487487
'markdown',
488-
'pandas<2.3.0',
488+
'pandas<2.4.0',
489489
'openai',
490490
'virtualenv-clone>=0.5,<1.0',
491491
],
@@ -496,7 +496,7 @@ def get_portability_package_data():
496496
'jinja2>=3.0,<3.2',
497497
'joblib>=1.0.1',
498498
'mock>=1.0.1,<6.0.0',
499-
'pandas<2.3.0',
499+
'pandas<2.4.0',
500500
'parameterized>=0.7.1,<0.10.0',
501501
'pydot>=1.2.0,<2',
502502
'pyhamcrest>=1.9,!=1.10.0,<3.0.0',

0 commit comments

Comments
 (0)