10000 Fix series with none equals float series by CloseChoice · Pull Request #44195 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

Fix series with none equals float series #44195

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
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add test for failing case
  • Loading branch information
CloseChoice committed Oct 26, 2021
commit f208db4b2afc63368f69bcc94bacdee701fb39e3
9 changes: 0 additions & 9 deletions pandas/_libs/lib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -620,39 +620,30 @@ def array_equivalent_object(left: object[:], right: object[:]) -> bool:
object x, y

for i in range(n):
# print('in array_equivalent_object')
x = left[i]
y = right[i]

# we are either not equal or both nan
# I think None == None will be true here
try:
# print('PyObject_RichCompareBool(x, y, Py_EQ): ' + str(PyObject_RichCompareBool(x, y, Py_EQ)))
# print('is_matching_na(x, y, nan_matches_none=True)' + str(is_matching_na(x, y, nan_matches_none=True)))
if PyArray_Check(x) and PyArray_Check(y):
if not array_equivalent_object(x, y):
# print('line 631, returning False, this is the index: ' + str(i))
return False
elif (x is C_NA) ^ (y is C_NA):
# print('first elif')
return False
elif not (
PyObject_RichCompareBool(x, y, Py_EQ)
or is_matching_na(x, y, nan_matches_none=True)
):
# print('second elif')
return False
except ValueError:
# print('raise Value Error')
# Avoid raising ValueError when comparing Numpy arrays to other types
if cnp.PyArray_IsAnyScalar(x) != cnp.PyArray_IsAnyScalar(y):
# Only compare scalars to scalars and non-scalars to non-scalars
# print('cnp.PyArray_IsAnyScalar(x) != cnp.PyArray_IsAnyScalar(y)')
return False
elif (not (cnp.PyArray_IsPythonScalar(x) or cnp.PyArray_IsPythonScalar(y))
and not (isinstance(x, type(y)) or isinstance(y, type(x)))):
# Check if non-scalars have the same type
# print('(not (cnp.PyArray_IsPythonScalar(x) or cnp.PyArray_IsPythonScalar(y)) and not (isinstance(x, type(y)) or isinstance(y, type(x)))):')
return False
raise
return True
Expand Down
7 changes: 0 additions & 7 deletions pandas/_libs/missing.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,16 @@ cpdef bint is_matching_na(object left, object right, bint nan_matches_none=False
bool
"""
if left is None:
# print('is matching na left is None')
if nan_matches_none and util.is_nan(right):
return True
return right is None
elif left is C_NA:
# print('is matching na left is C_NA')
return right is C_NA
elif left is NaT:
# print('is matching na left is NaT')
return right is NaT
elif util.is_float_object(left):
# print('is matching na left is float object')
if nan_matches_none and right is None and util.is_nan(left):
# print('is matching na left is float and right is None: actually right is ' + str(right))
return True
# print('is matching na left is float and right is NOT None')
# print('str(util.is_nan(left)): ' + str(str(util.is_nan(left))) + ' util.is_float_object(right) ' + str(util.is_float_object(right)) + ' util.is_nan(right) ' + str(util.is_nan(right)))
return (
util.is_nan(left)
and util.is_float_object(right)
Expand Down
1 change: 1 addition & 0 deletions pandas/tests/series/methods/test_equals.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def test_equals_none_vs_nan():
assert Index(ser, dtype=ser.dtype).equals(Index(ser2, dtype=ser2.dtype))
assert ser.array.equals(ser2.array)


def test_equals_None_vs_float():
left = Series([-np.inf, np.nan, -1.0, 0.0, 1.0, 10 / 3, np.inf], dtype=object)
right = Series([None] * len(left))
Expand Down
0