Skip to content

Commit aa9d0cf

Browse files
committed
BUG: various 32bit compat issues
closes #14866 xref #14183 Author: Jeff Reback <[email protected]> Closes #15766 from jreback/32bit and squashes the following commits: 93c03e3 [Jeff Reback] BUG: 32bit compat for .get_indexer 4163918 [Jeff Reback] BUG: fix isin for 32bit platform issues 1bb2f60 [Jeff Reback] BUG: cut/qcut should always return int64 bins
1 parent 1e753d7 commit aa9d0cf

File tree

5 files changed

+34
-21
lines changed

5 files changed

+34
-21
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 ``int64`` 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

pandas/tests/indexes/test_multi.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1359,7 +1359,7 @@ def test_hash_collisions(self):
13591359
names=['one', 'two'])
13601360
result = index.get_indexer(index.values)
13611361
self.assert_numpy_array_equal(result,
1362-
np.arange(len(index), dtype='int64'))
1362+
np.arange(len(index), dtype='intp'))
13631363

13641364
for i in [0, 1, len(index) - 2, len(index) - 1]:
13651365
result = index.get_loc(index[i])

pandas/tests/tools/test_tile.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ class TestCut(tm.TestCase):
1919
def test_simple(self):
2020
data = np.ones(5)
2121
result = cut(data, 4, labels=False)
22-
desired = np.array([1, 1, 1, 1, 1])
23-
tm.assert_numpy_array_equal(result, desired,
22+
expected = np.array([1, 1, 1, 1, 1])
23+
tm.assert_numpy_array_equal(result, expected,
2424
check_dtype=False)
2525

2626
def test_bins(self):

pandas/tools/tile.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from pandas.types.missing import isnull
66
from pandas.types.common import (is_float, is_integer,
7-
is_scalar)
7+
is_scalar, _ensure_int64)
88

99
from pandas.core.api import Series
1010
from pandas.core.categorical import Categorical
@@ -215,7 +215,7 @@ def _bins_to_cuts(x, bins, right=True, labels=None,
215215
bins = unique_bins
216216

217217
side = 'left' if right else 'right'
218-
ids = bins.searchsorted(x, side=side)
218+
ids = _ensure_int64(bins.searchsorted(x, side=side))
219219

220220
if include_lowest:
221221
ids[x == bins[0]] = 1

0 commit comments

Comments
 (0)