From bcdfb1d067ffb091d3f4ecd76e3be7a631c59c15 Mon Sep 17 00:00:00 2001 From: GujaLomsadze Date: Sat, 18 Jul 2026 12:40:15 +0200 Subject: [PATCH 1/3] GH-49255: [Python] Fix pandas Categorical DeprecationWarnings in tests --- python/pyarrow/tests/test_pandas.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/python/pyarrow/tests/test_pandas.py b/python/pyarrow/tests/test_pandas.py index 2a782de1648c..30387e09f1bb 100644 --- a/python/pyarrow/tests/test_pandas.py +++ b/python/pyarrow/tests/test_pandas.py @@ -3095,8 +3095,6 @@ def test_category(self): arrays = { 'cat_strings': pd.Categorical(v1 * repeats), - 'cat_strings_with_na': pd.Categorical(v1 * repeats, - categories=['foo', 'bar']), 'cat_ints': pd.Categorical(v2 * repeats), 'cat_binary': pd.Categorical(v3 * repeats), 'cat_strings_ordered': pd.Categorical( @@ -3121,8 +3119,8 @@ def _check(v): tm.assert_series_equal(pd.Series(result), pd.Series(v)) arrays = [ - pd.Categorical(['a', 'b', 'c'], categories=['a', 'b']), - pd.Categorical(['a', 'b', 'c'], categories=['a', 'b'], + pd.Categorical(['a', 'b', None], categories=['a', 'b']), + pd.Categorical(['a', 'b', None], categories=['a', 'b'], ordered=True) ] for arr in arrays: From ce2174e932fe82b215863a61362a86863fa04708 Mon Sep 17 00:00:00 2001 From: GujaLomsadze Date: Sat, 18 Jul 2026 15:22:51 +0200 Subject: [PATCH 2/3] GH-49255: [Python] Treat out-of-category Categorical deprecation as error --- python/setup.cfg | 2 ++ 1 file changed, 2 insertions(+) diff --git a/python/setup.cfg b/python/setup.cfg index 2d6558009b16..58e401185a8d 100644 --- a/python/setup.cfg +++ b/python/setup.cfg @@ -27,6 +27,8 @@ filterwarnings = error:The SparseDataFrame:FutureWarning # https://github.com/apache/arrow/issues/38239 ignore:Setting custom ClientSession:DeprecationWarning + # https://github.com/apache/arrow/issues/49255 + error:Constructing a Categorical with a dtype and values containing non-null entries:DeprecationWarning # Get a debug traceback when a test takes a really long time faulthandler_timeout = 300 From 9ecdde89a5c7c603a782deb6326b90f03ce997d7 Mon Sep 17 00:00:00 2001 From: GujaLomsadze Date: Sat, 18 Jul 2026 15:58:01 +0200 Subject: [PATCH 3/3] GH-49255: [Python] Add test asserting the Categorical deprecation is raised --- python/pyarrow/tests/test_pandas.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/python/pyarrow/tests/test_pandas.py b/python/pyarrow/tests/test_pandas.py index 30387e09f1bb..c3153e82b74b 100644 --- a/python/pyarrow/tests/test_pandas.py +++ b/python/pyarrow/tests/test_pandas.py @@ -3126,6 +3126,16 @@ def _check(v): for arr in arrays: _check(arr) + def test_category_construction_deprecation(self): + # GH-49255 + if Version(pd.__version__) < Version("3.0.0"): + pytest.skip("out-of-category deprecation added in pandas 3.0") + with pytest.warns( + DeprecationWarning, + match="Constructing a Categorical with a dtype and " + "values containing non-null entries"): + pd.Categorical(['a', 'b', 'c'], categories=['a', 'b']) + def test_empty_category(self): # ARROW-2443 df = pd.DataFrame({'cat': pd.Categorical([])})