Skip to content

Commit aa672b9

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

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

pandas/core/algorithms.py

Lines changed: 1 addition & 1 deletion
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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,24 @@ def test_categorical_from_codes(self):
615615
result = algos.isin(Sd, St)
616616
tm.assert_numpy_array_equal(expected, result)
617617

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

0 commit comments

Comments
 (0)