Skip to content

GH-49255: [Python] Fix pandas Categorical DeprecationWarnings in tests#50543

Merged
rok merged 3 commits into
apache:mainfrom
GujaLomsadze:fix-categorical-deprecation-49255
Jul 18, 2026
Merged

GH-49255: [Python] Fix pandas Categorical DeprecationWarnings in tests#50543
rok merged 3 commits into
apache:mainfrom
GujaLomsadze:fix-categorical-deprecation-49255

Conversation

@GujaLomsadze

@GujaLomsadze GujaLomsadze commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Rationale for this change

pandas 3.0.0 deprecated constructing or casting to a Categorical with
non-NA values that are not present in the specified dtype.categories.
This surfaces as DeprecationWarnings in the PyArrow
test suite when run against pandas >= 3.0 (GH-49255), in test_category
and test_category_implicit_from_pandas.

What changes are included in this PR?

  • test_category: remove the cat_strings_with_na column (relied on
    silent 'qux' -> NaN; redundant, cat_strings already carries nulls).
  • test_category_implicit_from_pandas: use explicit None
    (['a','b',None]) instead of out-of-category 'c'.

Are these changes tested?

Yes - test-only. Verified no DeprecationWarning under pandas 3.0.3.

Are there any user-facing changes?

No.

Closes #49255.

@GujaLomsadze

Copy link
Copy Markdown
Contributor Author

pandas-dev/pandas#40996

@rok rok left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems good, I would add erroring on deprecation warning to pytest perhaps so we don't backslide.

@rok
rok merged commit 59c3872 into apache:main Jul 18, 2026
36 checks passed
@rok rok removed the awaiting review Awaiting review label Jul 18, 2026
@AlenkaF

AlenkaF commented Jul 18, 2026

Copy link
Copy Markdown
Member

Yay, thanks for the contribution @GujaLomsadze! 🎉

@conbench-apache-arrow

Copy link
Copy Markdown

After merging your PR, Conbench analyzed the 4 benchmarking runs that have been run so far on merge-commit 59c3872.

There were no benchmark performance regressions. 🎉

The full Conbench report has more details. It also includes information about 44 possible false positives for unstable benchmarks that are known to sometimes produce them.

@raulcd

raulcd commented Jul 20, 2026

Copy link
Copy Markdown
Member

Thanks for the PR @GujaLomsadze !

rok pushed a commit that referenced this pull request Jul 22, 2026
…as 3.X deprecation (#50608)

### Rationale for this change
Follow-up to #50543. `test_categorical_order_survives_roundtrip` constructs a
`pd.Categorical` with value "a" not in categories `["b","c","d"]`. pandas 3.0.3
raises a deprecation for out-of-category values, which #50543's filterwarnings
config now turns into an error - failing nightly wheels across platforms.

### What changes are included in this PR?
Replace the out-of-category `"a"` value with an explicit `None`, preserving the
test's intent (ordered categorical with non-sorted categories survives a Parquet
roundtrip, ARROW-6302) plus a null.

### Are these changes tested?
Yes. Reproduced the failure with pandas 3.0.3, confirmed the test passes after
the change; all categorical tests in the module pass.

### Are there any user-facing changes?
No.

Closes #50579.
* GitHub Issue: #50579

Authored-by: Guja <127162872+GujaLomsadze@users.noreply.github.com>
Signed-off-by: Rok Mihevc <rok@mihevc.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Python] Fix DeprecationWarnings in PyArrow tests

4 participants