Skip to content

Allow None when nan_as_null=False in column constructor - #15709

Merged
rapids-bot[bot] merged 17 commits into
NVIDIA:branch-24.06from
galipremsagar:15708
May 15, 2024
Merged

Allow None when nan_as_null=False in column constructor#15709
rapids-bot[bot] merged 17 commits into
NVIDIA:branch-24.06from
galipremsagar:15708

Conversation

@galipremsagar

Copy link
Copy Markdown
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 requested a review from mroeschke May 9, 2024 19:55
@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 Python Affects Python cuDF API. label May 9, 2024
Comment thread python/cudf/cudf/core/column/column.py Outdated
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")

@galipremsagar galipremsagar May 9, 2024

Copy link
Copy Markdown
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?

Comment thread python/cudf/cudf/core/column/column.py Outdated
Comment thread python/cudf/cudf/core/column/column.py Outdated
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>
Comment thread python/cudf/cudf/core/column/column.py Outdated
Comment thread python/cudf/cudf/core/column/column.py Outdated
@galipremsagar
galipremsagar requested review from bdice and mroeschke May 10, 2024 13:16
Comment thread python/cudf/cudf/core/column/column.py Outdated
Comment thread python/cudf/cudf/core/column/column.py Outdated
Comment thread python/cudf/cudf/core/column/column.py Outdated
pd.isna(arbitrary).any()
any(
(isinstance(x, (np.floating, float)) and np.isnan(x))
or (inferred_dtype == "boolean" and pd.isna(arbitrary))

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.

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
Copy Markdown
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')

@galipremsagar
galipremsagar requested a review from mroeschke May 14, 2024 18:46
Comment thread python/cudf/cudf/core/column/column.py Outdated
@galipremsagar galipremsagar added the 5 - Ready to Merge Testing and reviews complete, ready to merge label May 14, 2024
Comment thread python/cudf/cudf/core/column/column.py Outdated
Comment thread python/cudf/cudf/core/column/column.py Outdated
f"Cannot have mixed values with {inferred_dtype}"
)
elif (
nan_as_null is False

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.

Don't compare to booleans with is.

Suggested change
nan_as_null is False
not nan_as_null

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Comment thread python/cudf/cudf/core/column/column.py Outdated
Comment thread python/cudf/cudf/core/column/column.py Outdated
Comment thread python/cudf/cudf/core/column/column.py Outdated
galipremsagar and others added 2 commits May 14, 2024 17:40
Co-authored-by: Bradley Dice <bdice@bradleydice.com>
@galipremsagar

Copy link
Copy Markdown
Contributor Author

/merge

@rapids-bot
rapids-bot Bot merged commit fa9d028 into NVIDIA:branch-24.06 May 15, 2024
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 non-breaking Non-breaking change Python Affects Python cuDF API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants