Skip to content

Commit 59a38d4

Browse files
committed
COMPAT: change neg of boolean to inv (deprecation in numpy 1.9)
COMPAT: remove deprecation warnings on __new__ (in computation/pytables)
1 parent 3b13646 commit 59a38d4

File tree

25 files changed

+65
-45
lines changed

25 files changed

+65
-45
lines changed

ci/script.sh

Lines changed: 7 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

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

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

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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 3 additions & 3 deletions
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,7 +280,7 @@ 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
@@ -363,7 +363,7 @@ def mask_missing(arr, values_to_mask):
363363
values_to_mask = np.array(values_to_mask, dtype=object)
364364

365365
na_mask = isnull(values_to_mask)
366-
nonna = values_to_mask[-na_mask]
366+
nonna = values_to_mask[~na_mask]
367367

368368
mask = None
369369
for x in nonna:

pandas/core/frame.py

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

Lines changed: 7 additions & 3 deletions
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

0 commit comments

Comments
 (0)