Skip to content

BUG: ensuring that np.asarray() simple handles data as objects and doesn't… #22161

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 6 commits into from
Aug 10, 2018
Merged
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
reworking test cases
  • Loading branch information
realead committed Aug 9, 2018
commit eb2da2018bc56afc9fbc0377952fe11db4ec75b9
34 changes: 30 additions & 4 deletions pandas/tests/test_algos.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,16 +617,42 @@ def test_categorical_from_codes(self):

def test_same_object_is_in(self):
# GH 22160
# nan is special, because out of a is a doesn't follow a == a
comps = ['ss', np.nan]
# nan is special, because from " a is b" doesn't follow "a == b"
# casting to -> np.float64 -> float-object will results in another nan-object
comps = [np.nan] # could be casted to float64
values = [np.nan]
expected = np.array([False, True])
expected = np.array([True])
result = algos.isin(comps, values)
tm.assert_numpy_array_equal(expected, result)

def test_different_nans(self):
# GH 22160
# the current behavior is:
# * list, array of objects: isin() is False for different nan-objects
# * array of float64s: isin() is True for all nans
# this behavior might be changed in the future
#
# this test case only ensures it doesn't happen accidentally
#
comps = [float('nan')]
values = [float('nan')]
assert comps[0] is not values[0] # different nan-objects

# as list of python-objects:
result = algos.isin(comps, values)
tm.assert_numpy_array_equal(np.array([False]), result)

# as object-array:
result = algos.isin(np.asarray(comps, dtype=np.object), np.asarray(values, dtype=np.object))
tm.assert_numpy_array_equal(np.array([False]), result)

#as float64-array:
result = algos.isin(np.asarray(comps, dtype=np.float64), np.asarray(values, dtype=np.float64))
tm.assert_numpy_array_equal(np.array([True]), result)

def test_no_cast(self):
# GH 22160
# ensure 42 is not casted to string
# ensure 42 is not casted to a string
comps = ['ss', 42]
values = ['42']
expected = np.array([False, False])
Expand Down