Skip to content

Commit be29fd2

Browse files
committed
Merge pull request pandas-dev#6960 from jreback/warnings
COMPAT: fix numpy 1.9-dev deprecation warnings in test suite
2 parents aaa592b + 3be3444 commit be29fd2

32 files changed

+244
-132
lines changed

ci/script.sh

+7
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ fi
1616
"$TRAVIS_BUILD_DIR"/ci/build_docs.sh 2>&1 > /tmp/doc.log &
1717
# doc build log will be shown after tests
1818

19+
# export the testing mode
20+
if [ -n "$NUMPY_BUILD" ]; then
21+
22+
export PANDAS_TESTING_MODE="numpy_deprecate"
23+
24+
fi
25+
1926
echo nosetests --exe -w /tmp -A "$NOSE_ARGS" pandas --with-xunit --xunit-file=/tmp/nosetests.xml
2027
nosetests --exe -w /tmp -A "$NOSE_ARGS" pandas --with-xunit --xunit-file=/tmp/nosetests.xml
2128

doc/source/release.rst

+3
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,9 @@ Prior Version Deprecations/Changes
240240
- Remove ``time_rule`` from several rolling-moment statistical functions, such
241241
as :func:`rolling_sum` (:issue:`1042`)
242242

243+
- Removed neg (-) boolean operations on numpy arrays in favor of inv (~), as this is going to
244+
be deprecated in numpy 1.9 (:issue:`6960`)
245+
243246
Experimental Features
244247
~~~~~~~~~~~~~~~~~~~~~
245248

doc/source/v0.14.0.txt

+2
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,8 @@ There are prior version deprecations that are taking effect as of 0.14.0.
368368
( `commit 3136390 <https://github.com/pydata/pandas/commit/3136390>`__ )
369369
- Remove ``time_rule`` from several rolling-moment statistical functions, such
370370
as :func:`rolling_sum` (:issue:`1042`)
371+
- Removed neg (-) boolean operations on numpy arrays in favor of inv (~), as this is going to
372+
be deprecated in numpy 1.9 (:issue:`6960`)
371373

372374
.. _whatsnew_0140.deprecations:
373375

pandas/algos.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ def rank_1d_generic(object in_arr, bint retry=1, ties_method='average',
510510
if not retry:
511511
raise
512512

513-
valid_locs = (-mask).nonzero()[0]
513+
valid_locs = (~mask).nonzero()[0]
514514
ranks.put(valid_locs, rank_1d_generic(values.take(valid_locs), 0,
515515
ties_method=ties_method,
516516
ascending=ascending))

pandas/computation/ops.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ class Term(StringMixin):
4242
def __new__(cls, name, env, side=None, encoding=None):
4343
klass = Constant if not isinstance(name, string_types) else cls
4444
supr_new = super(Term, klass).__new__
45-
if PY3:
46-
return supr_new(klass)
47-
return supr_new(klass, name, env, side=side, encoding=encoding)
45+
return supr_new(klass)
4846

4947
def __init__(self, name, env, side=None, encoding=None):
5048
self._name = name

pandas/computation/pytables.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ class Term(ops.Term):
3333
def __new__(cls, name, env, side=None, encoding=None):
3434
klass = Constant if not isinstance(name, string_types) else cls
3535
supr_new = StringMixin.__new__
36-
if PY3:
37-
return supr_new(klass)
38-
return supr_new(klass, name, env, side=side, encoding=encoding)
36+
return supr_new(klass)
3937

4038
def __init__(self, name, env, side=None, encoding=None):
4139
super(Term, self).__init__(name, env, side=side, encoding=encoding)

pandas/core/algorithms.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ def quantile(x, q, interpolation_method='fraction'):
329329
x = np.asarray(x)
330330
mask = com.isnull(x)
331331

332-
x = x[-mask]
332+
x = x[~mask]
333333

334334
values = np.sort(x)
335335

@@ -339,7 +339,7 @@ def _get_score(at):
339339

340340
idx = at * (len(values) - 1)
341341
if idx % 1 == 0:
342-
score = values[idx]
342+
score = values[int(idx)]
343343
else:
344344
if interpolation_method == 'fraction':
345345
score = _interpolate(values[int(idx)], values[int(idx) + 1],

pandas/core/common.py

+14-4
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ def _isnull_ndarraylike_old(obj):
248248
# this is the NaT pattern
249249
result = values.view('i8') == tslib.iNaT
250250
else:
251-
result = -np.isfinite(values)
251+
result = ~np.isfinite(values)
252252

253253
# box
254254
if isinstance(obj, ABCSeries):
@@ -280,12 +280,22 @@ def notnull(obj):
280280
res = isnull(obj)
281281
if np.isscalar(res):
282282
return not res
283-
return -res
283+
return ~res
284284

285285
def _is_null_datelike_scalar(other):
286286
""" test whether the object is a null datelike, e.g. Nat
287287
but guard against passing a non-scalar """
288-
return (np.isscalar(other) and (isnull(other) or other == tslib.iNaT)) or other is pd.NaT or other is None
288+
if other is pd.NaT or other is None:
289+
return True
290+
elif np.isscalar(other):
291+
292+
# a timedelta
293+
if hasattr(other,'dtype'):
294+
return other.view('i8') == tslib.iNaT
295+
elif is_integer(other) and other == tslib.iNaT:
296+
return True
297+
return isnull(other)
298+
return False
289299

290300
def array_equivalent(left, right):
291301
"""
@@ -363,7 +373,7 @@ def mask_missing(arr, values_to_mask):
363373
values_to_mask = np.array(values_to_mask, dtype=object)
364374

365375
na_mask = isnull(values_to_mask)
366-
nonna = values_to_mask[-na_mask]
376+
nonna = values_to_mask[~na_mask]
367377

368378
mask = None
369379
for x in nonna:

pandas/core/format.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1861,7 +1861,7 @@ def _get_format_timedelta64(values):
18611861
def impl(x):
18621862
if x is None or lib.checknull(x):
18631863
return 'NaT'
1864-
elif format_short and x == 0:
1864+
elif format_short and com.is_integer(x) and x.view('int64') == 0:
18651865
return "0 days" if even_days else "00:00:00"
18661866
else:
18671867
return lib.repr_timedelta64(x, format=format)

pandas/core/frame.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3041,7 +3041,7 @@ def update(self, other, join='left', overwrite=True, filter_func=None,
30413041
this = self[col].values
30423042
that = other[col].values
30433043
if filter_func is not None:
3044-
mask = -filter_func(this) | isnull(that)
3044+
mask = ~filter_func(this) | isnull(that)
30453045
else:
30463046
if raise_conflict:
30473047
mask_this = notnull(that)

pandas/core/generic.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,11 @@ def _indexed_same(self, other):
606606
for a in self._AXIS_ORDERS])
607607

608608
def __neg__(self):
609-
arr = operator.neg(_values_from_object(self))
609+
values = _values_from_object(self)
610+
if values.dtype == np.bool_:
611+
arr = operator.inv(values)
612+
else:
613+
arr = operator.neg(values)
610614
return self._wrap_array(arr, self.axes, copy=False)
611615

612616
def __invert__(self):
@@ -1459,10 +1463,10 @@ def drop(self, labels, axis=0, level=None, inplace=False, **kwargs):
14591463
if level is not None:
14601464
if not isinstance(axis, MultiIndex):
14611465
raise AssertionError('axis must be a MultiIndex')
1462-
indexer = -lib.ismember(axis.get_level_values(level),
1466+
indexer = ~lib.ismember(axis.get_level_values(level),
14631467
set(labels))
14641468
else:
1465-
indexer = -axis.isin(labels)
1469+
indexer = ~axis.isin(labels)
14661470

14671471
slicer = [slice(None)] * self.ndim
14681472
slicer[self._get_axis_number(axis_name)] = indexer

pandas/core/groupby.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1698,7 +1698,7 @@ def __init__(self, index, grouper=None, obj=None, name=None, level=None,
16981698

16991699
labels = np.empty(len(inds), dtype=inds.dtype)
17001700
labels[mask] = ok_labels
1701-
labels[-mask] = -1
1701+
labels[~mask] = -1
17021702

17031703
if len(uniques) < len(level_index):
17041704
level_index = level_index.take(uniques)

pandas/core/index.py

+29-29
Original file line numberDiff line numberDiff line change
@@ -480,10 +480,10 @@ def to_int():
480480
if is_integer(key):
481481
return key
482482
elif is_float(key):
483-
if not self.is_floating():
484-
warnings.warn("scalar indexers for index type {0} should be integers and not floating point".format(
485-
type(self).__name__),FutureWarning)
486-
return to_int()
483+
key = to_int()
484+
warnings.warn("scalar indexers for index type {0} should be integers and not floating point".format(
485+
type(self).__name__),FutureWarning)
486+
return key
487487
return self._convert_indexer_error(key, 'label')
488488

489489
if is_float(key):
@@ -498,17 +498,9 @@ def _validate_slicer(self, key, f):
498498
""" validate and raise if needed on a slice indexers according to the
499499
passed in function """
500500

501-
if not f(key.start):
502-
self._convert_indexer_error(key.start, 'slice start value')
503-
if not f(key.stop):
504-
self._convert_indexer_error(key.stop, 'slice stop value')
505-
if not f(key.step):
506-
self._convert_indexer_error(key.step, 'slice step value')
507-
508-
def _convert_slice_indexer_iloc(self, key):
509-
""" convert a slice indexer for iloc only """
510-
self._validate_slicer(key, lambda v: v is None or is_integer(v))
511-
return key
501+
for c in ['start','stop','step']:
502+
if not f(getattr(key,c)):
503+
self._convert_indexer_error(key.start, 'slice {0} value'.format(c))
512504

513505
def _convert_slice_indexer_getitem(self, key, is_index_slice=False):
514506
""" called from the getitem slicers, determine how to treat the key
@@ -520,6 +512,25 @@ def _convert_slice_indexer_getitem(self, key, is_index_slice=False):
520512
def _convert_slice_indexer(self, key, typ=None):
521513
""" convert a slice indexer. disallow floats in the start/stop/step """
522514

515+
# validate iloc
516+
if typ == 'iloc':
517+
518+
# need to coerce to_int if needed
519+
def f(c):
520+
v = getattr(key,c)
521+
if v is None or is_integer(v):
522+
return v
523+
524+
# warn if its a convertible float
525+
if v == int(v):
526+
warnings.warn("slice indexers when using iloc should be integers "
527+
"and not floating point",FutureWarning)
528+
return int(v)
529+
530+
self._convert_indexer_error(v, 'slice {0} value'.format(c))
531+
532+
return slice(*[ f(c) for c in ['start','stop','step']])
533+
523534
# validate slicers
524535
def validate(v):
525536
if v is None or is_integer(v):
@@ -530,7 +541,6 @@ def validate(v):
530541
return False
531542

532543
return True
533-
534544
self._validate_slicer(key, validate)
535545

536546
# figure out if this is a positional indexer
@@ -543,9 +553,7 @@ def is_int(v):
543553
is_index_slice = is_int(start) and is_int(stop)
544554
is_positional = is_index_slice and not self.is_integer()
545555

546-
if typ == 'iloc':
547-
return self._convert_slice_indexer_iloc(key)
548-
elif typ == 'getitem':
556+
if typ == 'getitem':
549557
return self._convert_slice_indexer_getitem(
550558
key, is_index_slice=is_index_slice)
551559

@@ -1980,7 +1988,7 @@ def _convert_slice_indexer(self, key, typ=None):
19801988
""" convert a slice indexer, by definition these are labels
19811989
unless we are iloc """
19821990
if typ == 'iloc':
1983-
return self._convert_slice_indexer_iloc(key)
1991+
return super(Float64Index, self)._convert_slice_indexer(key, typ=typ)
19841992

19851993
# allow floats here
19861994
self._validate_slicer(
@@ -2386,14 +2394,6 @@ def __unicode__(self):
23862394
def __len__(self):
23872395
return len(self.labels[0])
23882396

2389-
def _convert_slice_indexer(self, key, typ=None):
2390-
""" convert a slice indexer. disallow floats in the start/stop/step """
2391-
2392-
if typ == 'iloc':
2393-
return self._convert_slice_indexer_iloc(key)
2394-
2395-
return super(MultiIndex, self)._convert_slice_indexer(key, typ=typ)
2396-
23972397
def _get_names(self):
23982398
return FrozenList(level.name for level in self.levels)
23992399

@@ -2997,7 +2997,7 @@ def _drop_from_level(self, labels, level):
29972997
index = self.levels[i]
29982998
values = index.get_indexer(labels)
29992999

3000-
mask = -lib.ismember(self.labels[i], set(values))
3000+
mask = ~lib.ismember(self.labels[i], set(values))
30013001

30023002
return self[mask]
30033003

pandas/core/indexing.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import pandas.core.common as com
88
from pandas.core.common import (_is_bool_indexer, is_integer_dtype,
99
_asarray_tuplesafe, is_list_like, isnull,
10-
ABCSeries, ABCDataFrame, ABCPanel)
10+
ABCSeries, ABCDataFrame, ABCPanel, is_float)
1111
import pandas.lib as lib
1212

1313
import numpy as np
@@ -1319,6 +1319,7 @@ def _get_slice_axis(self, slice_obj, axis=0):
13191319
if not _need_slice(slice_obj):
13201320
return obj
13211321

1322+
slice_obj = self._convert_slice_indexer(slice_obj, axis)
13221323
if isinstance(slice_obj, slice):
13231324
return self._slice(slice_obj, axis=axis, typ='iloc')
13241325
else:
@@ -1363,7 +1364,15 @@ def _getitem_axis(self, key, axis=0, validate_iterable=False):
13631364

13641365
def _convert_to_indexer(self, obj, axis=0, is_setter=False):
13651366
""" much simpler as we only have to deal with our valid types """
1366-
if self._has_valid_type(obj, axis):
1367+
1368+
# make need to convert a float key
1369+
if isinstance(obj, slice):
1370+
return self._convert_slice_indexer(obj, axis)
1371+
1372+
elif is_float(obj):
1373+
return self._convert_scalar_indexer(obj, axis)
1374+
1375+
elif self._has_valid_type(obj, axis):
13671376
return obj
13681377

13691378
raise ValueError("Can only index by location with a [%s]" %

pandas/core/internals.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,7 @@ def to_native_types(self, slicer=None, na_rep='', float_format=None,
10491049
mask = isnull(values)
10501050
values[mask] = na_rep
10511051
if float_format:
1052-
imask = (-mask).ravel()
1052+
imask = (~mask).ravel()
10531053
values.flat[imask] = np.array(
10541054
[float_format % val for val in values.ravel()[imask]])
10551055
return values.tolist()
@@ -1181,7 +1181,7 @@ def to_native_types(self, slicer=None, na_rep=None, **kwargs):
11811181
if na_rep is None:
11821182
na_rep = 'NaT'
11831183
rvalues[mask] = na_rep
1184-
imask = (-mask).ravel()
1184+
imask = (~mask).ravel()
11851185
rvalues.flat[imask] = np.array([lib.repr_timedelta64(val)
11861186
for val in values.ravel()[imask]],
11871187
dtype=object)
@@ -1531,7 +1531,7 @@ def to_native_types(self, slicer=None, na_rep=None, date_format=None,
15311531
if na_rep is None:
15321532
na_rep = 'NaT'
15331533
rvalues[mask] = na_rep
1534-
imask = (-mask).ravel()
1534+
imask = (~mask).ravel()
15351535

15361536
if date_format is None:
15371537
date_formatter = lambda x: Timestamp(x)._repr_base

pandas/core/nanops.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,9 @@ def _isfinite(values):
190190
if issubclass(values.dtype.type, (np.timedelta64, np.datetime64)):
191191
return isnull(values)
192192
elif isinstance(values.dtype, object):
193-
return -np.isfinite(values.astype('float64'))
193+
return ~np.isfinite(values.astype('float64'))
194194

195-
return -np.isfinite(values)
195+
return ~np.isfinite(values)
196196

197197

198198
def _na_ok_dtype(dtype):

0 commit comments

Comments
 (0)