Skip to content

Fix all udf pytests - #21731

Merged
galipremsagar merged 3 commits into
NVIDIA:pandas3from
galipremsagar:udf_fixes
Mar 12, 2026
Merged

Fix all udf pytests#21731
galipremsagar merged 3 commits into
NVIDIA:pandas3from
galipremsagar:udf_fixes

Conversation

@galipremsagar

Copy link
Copy Markdown
Contributor

Description

This PR fixes type assertion issues in udf tests.
pandas3:

== 766 failed, 77673 passed, 19475 skipped, 1551 xfailed in 493.01s (0:08:13) ==

This PR:

== 486 failed, 77953 passed, 19475 skipped, 1551 xfailed in 486.86s (0:08:06) ==

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@galipremsagar galipremsagar self-assigned this Mar 10, 2026
@galipremsagar
galipremsagar requested a review from a team as a code owner March 10, 2026 15:42
@galipremsagar
galipremsagar removed the request for review from a team March 10, 2026 15:42
@galipremsagar galipremsagar added the 3 - Ready for Review Ready for review by team label Mar 10, 2026
@galipremsagar galipremsagar added improvement Improvement / enhancement to an existing function non-breaking Non-breaking change labels Mar 10, 2026
@galipremsagar
galipremsagar requested review from a team, mroeschke and vyasr March 10, 2026 15:42
@brandon-b-miller

Copy link
Copy Markdown
Contributor

@galipremsagar did the output type of UDFs change in pandas 3?

@github-actions github-actions Bot added the Python Affects Python cuDF API. label Mar 10, 2026
@galipremsagar

galipremsagar commented Mar 10, 2026

Copy link
Copy Markdown
Contributor Author

@galipremsagar did the output type of UDFs change in pandas 3?

That is not the real issue.

tm.assert_series_equal(left, right, check_dtype=False)
# Fails now

The core problem is that left is object dtype holding pd.NA values, while right is UInt64 (nullable integer). When pandas does the comparison with check_dtype=False, it casts UInt64 to float64 (turning NA into NaN), but pd.NA != NaN. Hence all these type-casts are needed.

@vyasr

vyasr commented Mar 10, 2026

Copy link
Copy Markdown
Contributor

Should we be putting this cast into our actual apply implementation? Otherwise we're going to have the same problems in the pandas test suite and we can't simply cast in the tests there, we need to actually match the output.

@brandon-b-miller

Copy link
Copy Markdown
Contributor

So will a any UDF that returns a null now return object dtype in pandas? I would think we'd get the nullable dtype with a true null.

@galipremsagar

galipremsagar commented Mar 10, 2026

Copy link
Copy Markdown
Contributor Author

So will a any UDF that returns a null now return object dtype in pandas? I would think we'd get the nullable dtype with a true null.

There is no change in dtypes returned by pandas or cudf udfs. The change happened in assert_series_equal API.

In [1]: import pandas as pd

In [2]: pd.__version__
Out[2]: '3.0.1'

In [3]: import numpy as np

In [4]: l = pd.Series([np.nan])

In [5]: r = pd.Series([pd.NA])

In [7]: pd.testing.assert_series_equal(l, r, check_dtype=False)
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
Cell In[7], line 1
----> 1 pd.testing.assert_series_equal(l, r, check_dtype=False)

    [... skipping hidden 2 frame]

File pandas/_libs/testing.pyx:53, in pandas._libs.testing.assert_almost_equal()

File pandas/_libs/testing.pyx:171, in pandas._libs.testing.assert_almost_equal()

File /raid/pgali/envs/cudfdev/lib/python3.13/site-packages/pandas/_testing/asserters.py:619, in raise_assert_detail(obj, message, left, right, diff, first_diff, index_values)
    616 if first_diff is not None:
    617     msg += f"\n{first_diff}"
--> 619 raise AssertionError(msg)

AssertionError: Series are different

Series values are different (100.0 %)
[index]: [0]
[left]:  [nan]
[right]: [<NA>]
At positional index 0, first diff: nan != <NA>
In [1]: import pandas as pd

In [2]: import numpy as np

In [3]: pd.__version__
Out[3]: '2.3.3'

In [4]: l = pd.Series([np.nan])

In [5]: r = pd.Series([pd.NA])

In [6]: pd.testing.assert_series_equal(l, r, check_dtype=False)
<ipython-input-6-ea3eeb97a7f8>:1: FutureWarning: Mismatched null-like values nan and <NA> found. In a future version, pandas equality-testing functions (e.g. assert_frame_equal) will consider these not-matching and raise.
  pd.testing.assert_series_equal(l, r, check_dtype=False)

Should we be putting this cast into our actual apply implementation? Otherwise we're going to have the same problems in the pandas test suite and we can't simply cast in the tests there, we need to actually match the output.

I agree that we should fix our apply to match pandas types, but in most cases pandas just returns object types for udf which means we will just have to raise MixedTypeError all across our udf's. I'd like to visit this angle if it is even worth raising in cudf or rather asking pandas to have them typed correctly once we get to there pandas test suite failures.

@vyasr vyasr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In the interest of the cudf test suite becoming usable again on the pandas3 branch I'm OK with changing the test for now, but we're just kicking the can a short way down the road since we'll have to deal with the pandas test suite very soon.

The style check is failing, make sure to fix that before merging.

@brandon-b-miller brandon-b-miller left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see whats happening here now, cuDF and pandas return the same thing but the equality comparison was going through non-nullable dtypes. This change seems fine to me.

@galipremsagar
galipremsagar merged commit 04fbe23 into NVIDIA:pandas3 Mar 12, 2026
5 of 7 checks passed
@GPUtester GPUtester moved this from Done to In Progress in cuDF Python Mar 12, 2026
@vyasr vyasr moved this from In Progress to Done in cuDF Python Mar 16, 2026
galipremsagar added a commit that referenced this pull request Mar 18, 2026
## Description
This PR fixes all pytest failures in `test_apply` similar to
#21731

This PR fixes 28 pytest failures.

## Checklist
- [x] I am familiar with the [Contributing
Guidelines](https://github.com/rapidsai/cudf/blob/HEAD/CONTRIBUTING.md).
- [x] New or existing tests cover these changes.
- [x] The documentation is up to date with these changes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3 - Ready for Review Ready for review by team improvement Improvement / enhancement to an existing function non-breaking Non-breaking change Python Affects Python cuDF API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants