-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
API: Coerce None according to the dtype of the container #7941
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
Merged
+224
−7
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -368,7 +368,7 @@ def _is_null_datelike_scalar(other): | |
return isnull(other) | ||
return False | ||
|
||
def array_equivalent(left, right): | ||
def array_equivalent(left, right, strict_nan=False): | ||
""" | ||
True if two arrays, left and right, have equal non-NaN elements, and NaNs in | ||
corresponding locations. False otherwise. It is assumed that left and right | ||
|
@@ -379,6 +379,8 @@ def array_equivalent(left, right): | |
Parameters | ||
---------- | ||
left, right : ndarrays | ||
strict_nan : bool, default False | ||
If True, consider NaN and None to be different. | ||
|
||
Returns | ||
------- | ||
|
@@ -394,11 +396,32 @@ def array_equivalent(left, right): | |
""" | ||
left, right = np.asarray(left), np.asarray(right) | ||
if left.shape != right.shape: return False | ||
# NaNs occur only in object arrays, float or complex arrays. | ||
|
||
# Object arrays can contain None, NaN and NaT. | ||
if issubclass(left.dtype.type, np.object_): | ||
return ((left == right) | (pd.isnull(left) & pd.isnull(right))).all() | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is good |
||
if not strict_nan: | ||
# pd.isnull considers NaN and None to be equivalent. | ||
return ((left == right) | (pd.isnull(left) & pd.isnull(right))).all() | ||
|
||
for left_value, right_value in zip(left, right): | ||
if left_value is tslib.NaT and right_value is not tslib.NaT: | ||
return False | ||
|
||
elif isinstance(left_value, float) and np.isnan(left_value): | ||
if not isinstance(right_value, float) or not np.isnan(right_value): | ||
return False | ||
else: | ||
if left_value != right_value: | ||
return False | ||
|
||
return True | ||
|
||
# NaNs can occur in float and complex arrays. | ||
if issubclass(left.dtype.type, (np.floating, np.complexfloating)): | ||
return ((left == right) | (np.isnan(left) & np.isnan(right))).all() | ||
|
||
# NaNs cannot occur otherwise. | ||
return np.array_equal(left, right) | ||
|
||
def _iterable_not_string(x): | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, this is good. Maybe add a small section (in missing.rst somewhere) showing this example? (and then put a link to it from here).
Also say that on a numeric/datetimelike
None
->Nan/NaT
(and not just integer series)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I've reworded this to say 'numeric', and added a section in missing.rst. There's already a mention of
NaT
below.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add this same section in a note in missing.rst somewhere (and then put a ref link in v0.15.0 to it, though leave the text here)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.