Skip to content

Commit 6f11ca6

Browse files
h-vetinariPingviinituutti
authored andcommitted
CLN/DEPS: Clean up post numpy bump to 1.12 (pandas-dev#23796)
1 parent 0496bc2 commit 6f11ca6

35 files changed

+40
-191
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ pip install pandas
171171
```
172172

173173
## Dependencies
174-
- [NumPy](https://www.numpy.org): 1.9.0 or higher
174+
- [NumPy](https://www.numpy.org): 1.12.0 or higher
175175
- [python-dateutil](https://labix.org/python-dateutil): 2.5.0 or higher
176176
- [pytz](https://pythonhosted.org/pytz): 2011k or higher
177177

ci/azure/linux.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
strategy:
1010
maxParallel: 11
1111
matrix:
12-
py27_np_19:
12+
py27_np_120:
1313
ENV_FILE: ci/deps/azure-27-compat.yaml
1414
CONDA_PY: "27"
1515
TEST_ARGS: "--skip-slow --skip-network"

pandas/_libs/algos_rank_helper.pxi.in

+1-9
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,7 @@ def rank_1d_{{dtype}}(object in_arr, ties_method='average',
102102
ranks = np.empty(n, dtype='f8')
103103

104104
{{if dtype == 'object'}}
105-
106-
try:
107-
_as = np.lexsort(keys=order)
108-
except TypeError:
109-
# lexsort on object array will raise TypeError for numpy version
110-
# earlier than 1.11.0. Use argsort with order argument instead.
111-
_dt = [('values', 'O'), ('mask', '?')]
112-
_values = np.asarray(list(zip(order[0], order[1])), dtype=_dt)
113-
_as = np.argsort(_values, kind='mergesort', order=('mask', 'values'))
105+
_as = np.lexsort(keys=order)
114106
{{else}}
115107
if tiebreak == TIEBREAK_FIRST:
116108
# need to use a stable sort here

pandas/_libs/lib.pyx

+1-3
Original file line numberDiff line numberDiff line change
@@ -518,9 +518,7 @@ def astype_intsafe(ndarray[object] arr, new_dtype):
518518
bint is_datelike
519519
ndarray result
520520

521-
# on 32-bit, 1.6.2 numpy M8[ns] is a subdtype of integer, which is weird
522-
is_datelike = new_dtype in ['M8[ns]', 'm8[ns]']
523-
521+
is_datelike = new_dtype == 'm8[ns]'
524522
result = np.empty(n, dtype=new_dtype)
525523
for i in range(n):
526524
val = arr[i]

pandas/_libs/sparse.pyx

-8
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,6 @@ from numpy cimport (ndarray, uint8_t, int64_t, int32_t, int16_t, int8_t,
88
cnp.import_array()
99

1010

11-
from distutils.version import LooseVersion
12-
13-
# numpy versioning
14-
_np_version = np.version.short_version
15-
_np_version_under1p10 = LooseVersion(_np_version) < LooseVersion('1.10')
16-
_np_version_under1p11 = LooseVersion(_np_version) < LooseVersion('1.11')
17-
18-
1911
# -----------------------------------------------------------------------------
2012
# Preamble stuff
2113

pandas/_libs/sparse_op_helper.pxi.in

-7
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,6 @@ cdef inline sparse_t __mod__(sparse_t a, sparse_t b):
4242
cdef inline sparse_t __floordiv__(sparse_t a, sparse_t b):
4343
if b == 0:
4444
if sparse_t is float64_t:
45-
# numpy >= 1.11 returns NaN
46-
# for a // 0, rather than +-inf
47-
if _np_version_under1p11:
48-
if a > 0:
49-
return INF
50-
elif a < 0:
51-
return -INF
5245
return NaN
5346
else:
5447
return 0

pandas/core/arrays/categorical.py

+2-10
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def f(self, other):
9898
ret[na_mask] = False
9999
return ret
100100

101-
# Numpy-1.9 and earlier may convert a scalar to a zerodim array during
101+
# Numpy < 1.13 may convert a scalar to a zerodim array during
102102
# comparison operation when second arg has higher priority, e.g.
103103
#
104104
# cat[0] < cat
@@ -2038,15 +2038,7 @@ def __setitem__(self, key, value):
20382038
elif isinstance(key, slice):
20392039
pass
20402040

2041-
# Array of True/False in Series or Categorical
2042-
else:
2043-
# There is a bug in numpy, which does not accept a Series as a
2044-
# indexer
2045-
# https://github.com/pandas-dev/pandas/issues/6168
2046-
# https://github.com/numpy/numpy/issues/4240 -> fixed in numpy 1.9
2047-
# FIXME: remove when numpy 1.9 is the lowest numpy version pandas
2048-
# accepts...
2049-
key = np.asarray(key)
2041+
# else: array of True/False in Series or Categorical
20502042

20512043
lindexer = self.categories.get_indexer(rvalue)
20522044
lindexer = self._maybe_coerce_indexer(lindexer)

pandas/core/arrays/datetimelike.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -835,8 +835,7 @@ def __isub__(self, other):
835835
def _evaluate_compare(self, other, op):
836836
"""
837837
We have been called because a comparison between
838-
8 aware arrays. numpy >= 1.11 will
839-
now warn about NaT comparisons
838+
8 aware arrays. numpy will warn about NaT comparisons
840839
"""
841840
# Called by comparison methods when comparing datetimelike
842841
# with datetimelike

pandas/core/arrays/sparse.py

-3
Original file line numberDiff line numberDiff line change
@@ -1015,9 +1015,6 @@ def __getitem__(self, key):
10151015
key = np.asarray(key)
10161016

10171017
if com.is_bool_indexer(key) and len(self) == len(key):
1018-
# TODO(numpy 1.11): Remove this asarray.
1019-
# Old NumPy didn't treat array-like as boolean masks.
1020-
key = np.asarray(key)
10211018
return self.take(np.arange(len(key), dtype=np.int32)[key])
10221019
elif hasattr(key, '__len__'):
10231020
return self.take(key)

pandas/core/dtypes/cast.py

+4-22
Original file line numberDiff line numberDiff line change
@@ -263,28 +263,10 @@ def maybe_promote(dtype, fill_value=np.nan):
263263
fill_value = np.nan
264264

265265
# returns tuple of (dtype, fill_value)
266-
if issubclass(dtype.type, (np.datetime64, np.timedelta64)):
267-
# for now: refuse to upcast datetime64
268-
# (this is because datetime64 will not implicitly upconvert
269-
# to object correctly as of numpy 1.6.1)
270-
if isna(fill_value):
271-
fill_value = iNaT
272-
else:
273-
if issubclass(dtype.type, np.datetime64):
274-
try:
275-
fill_value = tslibs.Timestamp(fill_value).value
276-
except Exception:
277-
# the proper thing to do here would probably be to upcast
278-
# to object (but numpy 1.6.1 doesn't do this properly)
279-
fill_value = iNaT
280-
elif issubclass(dtype.type, np.timedelta64):
281-
try:
282-
fill_value = tslibs.Timedelta(fill_value).value
283-
except Exception:
284-
# as for datetimes, cannot upcast to object
285-
fill_value = iNaT
286-
else:
287-
fill_value = iNaT
266+
if issubclass(dtype.type, np.datetime64):
267+
fill_value = tslibs.Timestamp(fill_value).value
268+
elif issubclass(dtype.type, np.timedelta64):
269+
fill_value = tslibs.Timedelta(fill_value).value
288270
elif is_datetimetz(dtype):
289271
if isna(fill_value):
290272
fill_value = iNaT

pandas/core/dtypes/dtypes.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -338,12 +338,7 @@ def _hash_categories(categories, ordered=True):
338338
cat_array = [cat_array]
339339
hashed = _combine_hash_arrays(iter(cat_array),
340340
num_items=len(cat_array))
341-
if len(hashed) == 0:
342-
# bug in Numpy<1.12 for length 0 arrays. Just return the correct
343-
# value of 0
344-
return 0
345-
else:
346-
return np.bitwise_xor.reduce(hashed)
341+
return np.bitwise_xor.reduce(hashed)
347342

348343
@classmethod
349344
def construct_array_type(cls):

pandas/core/indexes/datetimes.py

-5
Original file line numberDiff line numberDiff line change
@@ -415,11 +415,6 @@ def __setstate__(self, state):
415415
self._freq = own_state[1]
416416
self._tz = timezones.tz_standardize(own_state[2])
417417

418-
# provide numpy < 1.7 compat
419-
if nd_state[2] == 'M8[us]':
420-
new_state = np.ndarray.__reduce__(data.astype('M8[ns]'))
421-
np.ndarray.__setstate__(data, new_state[2])
422-
423418
else: # pragma: no cover
424419
data = np.empty(state)
425420
np.ndarray.__setstate__(data, state)

pandas/core/internals/blocks.py

+2-20
Original file line numberDiff line numberDiff line change
@@ -1458,11 +1458,6 @@ def quantile(self, qs, interpolation='linear', axis=0, axes=None):
14581458

14591459
def _nanpercentile1D(values, mask, q, **kw):
14601460
# mask is Union[ExtensionArray, ndarray]
1461-
# we convert to an ndarray for NumPy 1.9 compat, which didn't
1462-
# treat boolean-like arrays as boolean. This conversion would have
1463-
# been done inside ndarray.__getitem__ anyway, since values is
1464-
# an ndarray at this point.
1465-
mask = np.asarray(mask)
14661461
values = values[~mask]
14671462

14681463
if len(values) == 0:
@@ -2781,9 +2776,7 @@ def set(self, locs, values, check=False):
27812776
-------
27822777
None
27832778
"""
2784-
if values.dtype != _NS_DTYPE:
2785-
# Workaround for numpy 1.6 bug
2786-
values = conversion.ensure_datetime64ns(values)
2779+
values = conversion.ensure_datetime64ns(values, copy=False)
27872780

27882781
self.values[locs] = values
27892782

@@ -3102,7 +3095,7 @@ def _merge_blocks(blocks, dtype=None, _can_consolidate=True):
31023095
# FIXME: optimization potential in case all mgrs contain slices and
31033096
# combination of those slices is a slice, too.
31043097
new_mgr_locs = np.concatenate([b.mgr_locs.as_array for b in blocks])
3105-
new_values = _vstack([b.values for b in blocks], dtype)
3098+
new_values = np.vstack([b.values for b in blocks])
31063099

31073100
argsort = np.argsort(new_mgr_locs)
31083101
new_values = new_values[argsort]
@@ -3114,17 +3107,6 @@ def _merge_blocks(blocks, dtype=None, _can_consolidate=True):
31143107
return blocks
31153108

31163109

3117-
def _vstack(to_stack, dtype):
3118-
3119-
# work around NumPy 1.6 bug
3120-
if dtype == _NS_DTYPE or dtype == _TD_DTYPE:
3121-
new_values = np.vstack([x.view('i8') for x in to_stack])
3122-
return new_values.view(dtype)
3123-
3124-
else:
3125-
return np.vstack(to_stack)
3126-
3127-
31283110
def _block2d_to_blocknd(values, placement, shape, labels, ref_items):
31293111
""" pivot to the labels shape """
31303112
panel_shape = (len(placement),) + shape

pandas/core/internals/managers.py

+4-24
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,6 @@ def __getstate__(self):
248248

249249
def __setstate__(self, state):
250250
def unpickle_block(values, mgr_locs):
251-
# numpy < 1.7 pickle compat
252-
if values.dtype == 'M8[us]':
253-
values = values.astype('M8[ns]')
254251
return make_block(values, placement=mgr_locs)
255252

256253
if (isinstance(state, tuple) and len(state) >= 4 and
@@ -776,18 +773,6 @@ def _interleave(self):
776773

777774
result = np.empty(self.shape, dtype=dtype)
778775

779-
if result.shape[0] == 0:
780-
# Workaround for numpy 1.7 bug:
781-
#
782-
# >>> a = np.empty((0,10))
783-
# >>> a[slice(0,0)]
784-
# array([], shape=(0, 10), dtype=float64)
785-
# >>> a[[]]
786-
# Traceback (most recent call last):
787-
# File "<stdin>", line 1, in <module>
788-
# IndexError: index 0 is out of bounds for axis 0 with size 0
789-
return result
790-
791776
itemmask = np.zeros(self.shape[0])
792777

793778
for blk in self.blocks:
@@ -1170,8 +1155,7 @@ def insert(self, loc, item, value, allow_duplicates=False):
11701155
blk.mgr_locs = new_mgr_locs
11711156

11721157
if loc == self._blklocs.shape[0]:
1173-
# np.append is a lot faster (at least in numpy 1.7.1), let's use it
1174-
# if we can.
1158+
# np.append is a lot faster, let's use it if we can.
11751159
self._blklocs = np.append(self._blklocs, 0)
11761160
self._blknos = np.append(self._blknos, len(self.blocks))
11771161
else:
@@ -1995,13 +1979,9 @@ def _transform_index(index, func, level=None):
19951979

19961980
def _fast_count_smallints(arr):
19971981
"""Faster version of set(arr) for sequences of small numbers."""
1998-
if len(arr) == 0:
1999-
# Handle empty arr case separately: numpy 1.6 chokes on that.
2000-
return np.empty((0, 2), dtype=arr.dtype)
2001-
else:
2002-
counts = np.bincount(arr.astype(np.int_))
2003-
nz = counts.nonzero()[0]
2004-
return np.c_[nz, counts[nz]]
1982+
counts = np.bincount(arr.astype(np.int_))
1983+
nz = counts.nonzero()[0]
1984+
return np.c_[nz, counts[nz]]
20051985

20061986

20071987
def _preprocess_slice_or_indexer(slice_or_indexer, length, allow_fill):

pandas/core/reshape/tile.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,7 @@ def _bins_to_cuts(x, bins, right=True, labels=None,
334334
ids = ensure_int64(bins.searchsorted(x, side=side))
335335

336336
if include_lowest:
337-
# Numpy 1.9 support: ensure this mask is a Numpy array
338-
ids[np.asarray(x == bins[0])] = 1
337+
ids[x == bins[0]] = 1
339338

340339
na_mask = isna(x) | (ids == len(bins)) | (ids == 0)
341340
has_nas = na_mask.any()

pandas/io/packers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ def dtype_for(t):
250250
'complex128': np.float64,
251251
'complex64': np.float32}
252252

253-
# numpy 1.6.1 compat
253+
# windows (32 bit) compat
254254
if hasattr(np, 'float128'):
255255
c2f_dict['complex256'] = np.float128
256256

pandas/io/pickle.py

-8
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
from pandas.compat import PY3, BytesIO, cPickle as pkl, pickle_compat as pc
88

9-
from pandas.core.dtypes.common import _NS_DTYPE, is_datetime64_dtype
10-
119
from pandas.io.common import _get_handle, _stringify_path
1210

1311

@@ -200,10 +198,4 @@ def _pickle_array(arr):
200198
def _unpickle_array(bytes):
201199
arr = read_array(BytesIO(bytes))
202200

203-
# All datetimes should be stored as M8[ns]. When unpickling with
204-
# numpy1.6, it will read these as M8[us]. So this ensures all
205-
# datetime64 types are read as MS[ns]
206-
if is_datetime64_dtype(arr):
207-
arr = arr.view(_NS_DTYPE)
208-
209201
return arr

pandas/plotting/_misc.py

-3
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,6 @@ def scatter_matrix(frame, alpha=0.5, figsize=None, ax=None, grid=False,
138138

139139
def _get_marker_compat(marker):
140140
import matplotlib.lines as mlines
141-
import matplotlib as mpl
142-
if mpl.__version__ < '1.1.0' and marker == '.':
143-
return 'o'
144141
if marker not in mlines.lineMarkers:
145142
return 'o'
146143
return marker

pandas/tests/arrays/categorical/test_repr.py

-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ def test_big_print(self):
3737
def test_empty_print(self):
3838
factor = Categorical([], ["a", "b", "c"])
3939
expected = ("[], Categories (3, object): [a, b, c]")
40-
# hack because array_repr changed in numpy > 1.6.x
4140
actual = repr(factor)
4241
assert actual == expected
4342

pandas/tests/dtypes/test_inference.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -1272,10 +1272,7 @@ def test_nan_to_nat_conversions():
12721272
s._data = s._data.setitem(indexer=tuple([slice(8, 9)]), value=np.nan)
12731273
assert (isna(s[8]))
12741274

1275-
# numpy < 1.7.0 is wrong
1276-
from distutils.version import LooseVersion
1277-
if LooseVersion(np.__version__) >= LooseVersion('1.7.0'):
1278-
assert (s[8].value == np.datetime64('NaT').astype(np.int64))
1275+
assert (s[8].value == np.datetime64('NaT').astype(np.int64))
12791276

12801277

12811278
@td.skip_if_no_scipy

pandas/tests/frame/test_constructors.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
from pandas.core.dtypes.common import is_integer_dtype
1717
from pandas.compat import (lmap, long, zip, range, lrange, lzip,
18-
OrderedDict, is_platform_little_endian, PY36)
18+
OrderedDict, is_platform_little_endian, PY3, PY36)
1919
from pandas import compat
2020
from pandas import (DataFrame, Index, Series, isna,
2121
MultiIndex, Timedelta, Timestamp,
@@ -164,9 +164,9 @@ def test_constructor_dtype_str_na_values(self, string_dtype):
164164

165165
def test_constructor_rec(self):
166166
rec = self.frame.to_records(index=False)
167-
168-
# Assigning causes segfault in NumPy < 1.5.1
169-
# rec.dtype.names = list(rec.dtype.names)[::-1]
167+
if PY3:
168+
# unicode error under PY2
169+
rec.dtype.names = list(rec.dtype.names)[::-1]
170170

171171
index = self.frame.index
172172

pandas/tests/frame/test_operators.py

-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ def _check_unary_op(op):
190190
_check_bin_op(operator.or_)
191191
_check_bin_op(operator.xor)
192192

193-
# operator.neg is deprecated in numpy >= 1.9
194193
_check_unary_op(operator.inv) # TODO: belongs elsewhere
195194

196195
def test_logical_with_nas(self):

pandas/tests/indexes/common.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -663,12 +663,9 @@ def test_equals_op(self):
663663
tm.assert_series_equal(series_a == item, Series(expected3))
664664

665665
def test_numpy_ufuncs(self):
666-
# test ufuncs of numpy 1.9.2. see:
666+
# test ufuncs of numpy, see:
667667
# http://docs.scipy.org/doc/numpy/reference/ufuncs.html
668668

669-
# some functions are skipped because it may return different result
670-
# for unicode input depending on numpy version
671-
672669
for name, idx in compat.iteritems(self.indices):
673670
for func in [np.exp, np.exp2, np.expm1, np.log, np.log2, np.log10,
674671
np.log1p, np.sqrt, np.sin, np.cos, np.tan, np.arcsin,

0 commit comments

Comments
 (0)