Skip to content

Commit 4163918

Browse files
committed
BUG: fix isin for 32bit platform issues
1 parent 1bb2f60 commit 4163918

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

doc/source/whatsnew/v0.20.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,7 @@ Bug Fixes
824824
- Bug in ``pd.qcut()`` with a single quantile and an array with identical values (:issue:`15431`)
825825
- Compat with SciPy 0.19.0 for testing on ``.interpolate()`` (:issue:`15662`)
826826

827+
- Compat for 32-bit platforms for ``.qcut/cut``; bins will now be ``in64`` dtype (:issue:`14866`)
827828

828829
- Bug in the display of ``.info()`` where a qualifier (+) would always be displayed with a ``MultiIndex`` that contains only non-strings (:issue:`15245`)
829830
- Bug in ``.replace()`` may result in incorrect dtypes. (:issue:`12747`, :issue:`15765`)

pandas/core/algorithms.py

+28-16
Original file line numberDiff line numberDiff line change
@@ -169,33 +169,45 @@ def isin(comps, values):
169169
raise TypeError("only list-like objects are allowed to be passed"
170170
" to isin(), you passed a "
171171
"[{0}]".format(type(comps).__name__))
172-
comps = np.asarray(comps)
173172
if not is_list_like(values):
174173
raise TypeError("only list-like objects are allowed to be passed"
175174
" to isin(), you passed a "
176175
"[{0}]".format(type(values).__name__))
177-
if not isinstance(values, np.ndarray):
178-
values = list(values)
176+
177+
from pandas import DatetimeIndex, PeriodIndex
178+
179+
if not isinstance(values, (ABCIndex, ABCSeries, np.ndarray)):
180+
values = np.array(list(values), dtype='object')
181+
182+
if needs_i8_conversion(comps):
183+
if is_period_dtype(values):
184+
comps = PeriodIndex(comps)
185+
values = PeriodIndex(values)
186+
else:
187+
comps = DatetimeIndex(comps)
188+
values = DatetimeIndex(values)
189+
190+
values = values.asi8
191+
comps = comps.asi8
192+
elif is_bool_dtype(comps):
193+
194+
try:
195+
comps = np.asarray(comps).view('uint8')
196+
values = np.asarray(values).view('uint8')
197+
except TypeError:
198+
# object array conversion will fail
199+
pass
200+
else:
201+
comps = np.asarray(comps)
202+
values = np.asarray(values)
179203

180204
# GH11232
181205
# work-around for numpy < 1.8 and comparisions on py3
182206
# faster for larger cases to use np.in1d
183207
if (_np_version_under1p8 and compat.PY3) or len(comps) > 1000000:
184208
f = lambda x, y: np.in1d(x, np.asarray(list(y)))
185-
else:
186-
f = lambda x, y: lib.ismember_int64(x, set(y))
187-
188-
# may need i8 conversion for proper membership testing
189-
if is_datetime64_dtype(comps):
190-
from pandas.tseries.tools import to_datetime
191-
values = to_datetime(values)._values.view('i8')
192-
comps = comps.view('i8')
193-
elif is_timedelta64_dtype(comps):
194-
from pandas.tseries.timedeltas import to_timedelta
195-
values = to_timedelta(values)._values.view('i8')
196-
comps = comps.view('i8')
197209
elif is_int64_dtype(comps):
198-
pass
210+
f = lambda x, y: lib.ismember_int64(x, set(y))
199211
else:
200212
f = lambda x, y: lib.ismember(x, set(values))
201213

0 commit comments

Comments
 (0)