Skip to content

Commit 9043508

Browse files
committed
BUG: ensuring that np.asarray() simple handles data as objects and doesn't try to do smart things (GH22160)
1 parent d30c4a0 commit 9043508

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

pandas/core/algorithms.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def _ensure_data(values, dtype=None):
134134
return values, dtype, 'int64'
135135

136136
# we have failed, return object
137-
values = np.asarray(values)
137+
values = np.asarray(values, dtype=np.object)
138138
return ensure_object(values), 'object', 'object'
139139

140140

pandas/tests/test_algos.py

+18
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,24 @@ def test_categorical_from_codes(self):
614614
result = algos.isin(Sd, St)
615615
tm.assert_numpy_array_equal(expected, result)
616616

617+
def test_same_object_is_in(self):
618+
# GH 22160
619+
# nan is special, because out of a is a doesn't follow a == a
620+
comps = ['ss', np.nan]
621+
values = [np.nan]
622+
expected = np.array([False, True])
623+
result = algos.isin(comps, values)
624+
tm.assert_numpy_array_equal(expected, result)
625+
626+
def test_no_cast(self):
627+
# GH 22160
628+
# ensure 42 is not casted to string
629+
comps = ['ss', 42]
630+
values = ['42']
631+
expected = np.array([False, False])
632+
result = algos.isin(comps, values)
633+
tm.assert_numpy_array_equal(expected, result)
634+
617635
@pytest.mark.parametrize("empty", [[], Series(), np.array([])])
618636
def test_empty(self, empty):
619637
# see gh-16991

0 commit comments

Comments
 (0)