Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow None when nan_as_null=False in column constructor #15709

Merged
merged 17 commits into from
May 15, 2024

Conversation

galipremsagar
Copy link
Contributor

Description

Fixes: #15708

This PR fixes an issue where we were throwing an error when None is present and nan_as_null=False, this is a bug because of using pd.isna, this returns True for nan, None and NA. Whereas we are only looking for np.nan and not None and pd.NA

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 added bug Something isn't working non-breaking Non-breaking change labels May 9, 2024
@galipremsagar galipremsagar added this to the cudf.pandas API coverage milestone May 9, 2024
@galipremsagar galipremsagar self-assigned this May 9, 2024
@galipremsagar galipremsagar requested a review from a team as a code owner May 9, 2024 19:55
@galipremsagar galipremsagar requested a review from isVoid May 9, 2024 19:55
@galipremsagar galipremsagar changed the title Allow None when nan_as_null=False Allow None when nan_as_null=False in column constructor May 9, 2024
@github-actions github-actions bot added the cuDF (Python) Affects Python cuDF API. label May 9, 2024
Comment on lines 1959 to 1963
elif nan_as_null is False and (
pd.isna(arbitrary).any()
and inferred_dtype not in ("decimal", "empty")
and inferred_dtype not in ("decimal", "empty", "string")
):
# Decimal can hold float("nan")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mroeschke After the changes in this PR, do you think this block might be redundant or does it still capture some error scenarios?

python/cudf/cudf/core/column/column.py Outdated Show resolved Hide resolved
python/cudf/cudf/core/column/column.py Outdated Show resolved Hide resolved
galipremsagar and others added 2 commits May 9, 2024 15:16
Co-authored-by: Bradley Dice <bdice@bradleydice.com>
Co-authored-by: Bradley Dice <bdice@bradleydice.com>
pd.isna(arbitrary).any()
any(
(isinstance(x, (np.floating, float)) and np.isnan(x))
or (inferred_dtype == "boolean" and pd.isna(arbitrary))
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be good to have (inferred_dtype == "boolean" and pd.isna(arbitrary)) be evaluated outside the loop.

Also what case is this condition trying to catch?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Also what case is this condition trying to catch?

It is trying to catch this case:

pd.Series(["a", "b", np.nan], dtype='object')

python/cudf/cudf/core/column/column.py Outdated Show resolved Hide resolved
@galipremsagar galipremsagar added the 5 - Ready to Merge Testing and reviews complete, ready to merge label May 14, 2024
python/cudf/cudf/core/column/column.py Outdated Show resolved Hide resolved
python/cudf/cudf/core/column/column.py Outdated Show resolved Hide resolved
f"Cannot have mixed values with {inferred_dtype}"
)
elif (
nan_as_null is False
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't compare to booleans with is.

Suggested change
nan_as_null is False
not nan_as_null

Copy link
Contributor Author

Choose a reason for hiding this comment

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

raise MixedTypeError(
f"Cannot have mixed values with {inferred_dtype}"
)
elif nan_as_null is False and _has_any_nan(arbitrary):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
elif nan_as_null is False and _has_any_nan(arbitrary):
elif not nan_as_null and _has_any_nan(arbitrary):

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need this comparison because None is also a supported parameter and it is similar to True behavior.

python/cudf/cudf/core/column/column.py Outdated Show resolved Hide resolved
python/cudf/cudf/core/column/column.py Outdated Show resolved Hide resolved
python/cudf/cudf/core/column/column.py Outdated Show resolved Hide resolved
galipremsagar and others added 2 commits May 14, 2024 17:40
Co-authored-by: Bradley Dice <bdice@bradleydice.com>
@galipremsagar
Copy link
Contributor Author

/merge

@rapids-bot rapids-bot bot merged commit fa9d028 into rapidsai:branch-24.06 May 15, 2024
70 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5 - Ready to Merge Testing and reviews complete, ready to merge bug Something isn't working cuDF (Python) Affects Python cuDF API. non-breaking Non-breaking change
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[BUG] cudf.Series should accept None values when nan_as_null=False
3 participants