Repository navigation
[Python] test_categorical_order_survives_roundtrip fails on wheels with Pandas Deprecation #50579
Copy link
Copy link
Closed
Description
Describe the bug, including details regarding any error messages, version, and platform.
Several nightly wheels:
- wheel-macos-monterey-cp311-cp311-amd64
- wheel-macos-monterey-cp311-cp311-arm64
- wheel-macos-monterey-cp312-cp312-amd64
- wheel-macos-monterey-cp314-cp314t-amd64
- wheel-manylinux-2-28-cp311-cp311-amd64
- wheel-manylinux-2-28-cp311-cp311-arm64
- wheel-manylinux-2-28-cp312-cp312-amd64
- wheel-manylinux-2-28-cp312-cp312-arm64
- wheel-musllinux-1-2-cp311-cp311-arm64
- wheel-windows-cp311-cp311-amd64
- wheel-windows-cp312-cp312-amd64
- wheel-windows-cp313-cp313-amd64
- wheel-windows-cp314-cp314-amd64
- wheel-windows-cp314-cp314t-amd64
Have failed during the last nightlies with:
__________________ test_categorical_order_survives_roundtrip ___________________
@pytest.mark.pandas
def test_categorical_order_survives_roundtrip():
# ARROW-6302
> df = pd.DataFrame({"a": pd.Categorical(
["a", "b", "c", "a"], categories=["b", "c", "d"], ordered=True)})
/tmp/arrow-HEAD.ZW7lN/venv-wheel-3.12-manylinux_2_28_x86_64/lib64/python3.12/site-packages/pyarrow/tests/parquet/test_pandas.py:474:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/tmp/arrow-HEAD.ZW7lN/venv-wheel-3.12-manylinux_2_28_x86_64/lib64/python3.12/site-packages/pandas/core/arrays/categorical.py:504: in __init__
codes = _get_codes_for_values(values, dtype.categories)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
values = <ArrowStringArray>
['a', 'b', 'c', 'a']
Length: 4, dtype: str
categories = Index(['b', 'c', 'd'], dtype='str')
def _get_codes_for_values(
values: Index | Series | ExtensionArray | np.ndarray,
categories: Index,
) -> np.ndarray:
"""
utility routine to turn values into codes given the specified categories
If `values` is known to be a Categorical, use recode_for_categories instead.
"""
codes = categories.get_indexer_for(values)
wrong = (codes == -1) & ~isna(values)
if wrong.any():
> warnings.warn(
"Constructing a Categorical with a dtype and values containing "
"non-null entries not in that dtype's categories is deprecated "
"and will raise in a future version.",
Pandas4Warning,
stacklevel=find_stack_level(),
)
E pandas.errors.Pandas4Warning: Constructing a Categorical with a dtype and values containing non-null entries not in that dtype's categories is deprecated and will raise in a future version.
/tmp/arrow-HEAD.ZW7lN/venv-wheel-3.12-manylinux_2_28_x86_64/lib64/python3.12/site-packages/pandas/core/arrays/categorical.py:3045: Pandas4WarningThe one investigated seems to be using:
Downloading pandas-3.0.3-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (10.9 MB)
Component(s)
Python
Reactions are currently unavailable
Activity
raulcd commentedon Jul 22, 2026
It seems this is related to the changes on this PR:
We should probably filter this warning on
test_categorical_order_survives_roundtripor fix the underlying code.cc @GujaLomsadze @rok @AlenkaF
rok commentedon Jul 22, 2026
Most likely it is related. IIRC it's better to change the test to either catch the warning or remove the reason it's throwing the warning. @GujaLomsadze do you want to tackle this one?
GujaLomsadze commentedon Jul 22, 2026
I will take this one, thanks!
GujaLomsadze commentedon Jul 22, 2026
take
apacheGH-50579: [Python] Fix test_categorical_order_survives_roundtri…
GH-50579: [Python] Fix test_categorical_order_survives_roundtrip pand…
rok commentedon Jul 22, 2026
Issue resolved by pull request 50608
#50608