Skip to content

[Python] test_categorical_order_survives_roundtrip fails on wheels with Pandas Deprecation #50579

Closed

Description

@raulcd

Describe the bug, including details regarding any error messages, version, and platform.

Several nightly wheels:

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: Pandas4Warning

The 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

Activity

  1. raulcd commented on Jul 22, 2026

    @raulcd
    MemberAuthor

    It seems this is related to the changes on this PR:

    We should probably filter this warning on test_categorical_order_survives_roundtrip or fix the underlying code.

    cc @GujaLomsadze @rok @AlenkaF

  2. rok commented on Jul 22, 2026

    @rok
    Member

    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?

  3. GujaLomsadze commented on Jul 22, 2026

    @GujaLomsadze
    Contributor

    I will take this one, thanks!

  4. GujaLomsadze commented on Jul 22, 2026

    @GujaLomsadze
    Contributor

    take

  5. added a commit that references this issue on Jul 22, 2026
  6. added a commit that references this issue on Jul 22, 2026
  7. added this to the 26.0.0 milestone on Jul 22, 2026
  8. rok commented on Jul 22, 2026

    @rok
    Member

    Issue resolved by pull request 50608
    #50608

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions