Skip to content

Commit effb676

Browse files
committed
misc import cleanups
1 parent 0bd25ab commit effb676

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

doc/source/whatsnew/v0.17.0.txt

+3-2
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,6 @@ Other API Changes
230230
- Enable serialization of lists and dicts to strings in ExcelWriter (:issue:`8188`)
231231
- Allow passing `kwargs` to the interpolation methods (:issue:`10378`).
232232
- Serialize metadata properties of subclasses of pandas objects (:issue:`10553`).
233-
- Boolean comparisons of a ``Series`` vs ``None`` will now be equivalent to comparing with ``np.nan``, rather than raise ``TypeError``, xref (:issue:`1079`).
234-
- Remove use of some deprecated numpy comparisons (:issue:`10569`)
235233

236234
.. _whatsnew_0170.deprecations:
237235

@@ -243,6 +241,8 @@ Deprecations
243241
Removal of prior version deprecations/changes
244242
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
245243

244+
- Remove use of some deprecated numpy comparison operations, mainly in tests. (:issue:`10569`)
245+
246246
.. _dask: https://dask.readthedocs.org/en/latest/
247247

248248
.. _whatsnew_0170.gil:
@@ -285,6 +285,7 @@ Performance Improvements
285285
Bug Fixes
286286
~~~~~~~~~
287287

288+
- Boolean comparisons of a ``Series`` vs ``None`` will now be equivalent to comparing with ``np.nan``, rather than raise ``TypeError``, xref (:issue:`1079`).
288289
- Bug in ``DataFrame.apply`` when function returns categorical series. (:issue:`9573`)
289290
- Bug in ``to_datetime`` with invalid dates and formats supplied (:issue:`10154`)
290291
- Bug in ``Index.drop_duplicates`` dropping name(s) (:issue:`10115`)

pandas/core/ops.py

+20-18
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
from pandas.tslib import iNaT
1818
from pandas.core.common import(bind_method, is_list_like, notnull, isnull,
1919
_values_from_object, _maybe_match_name,
20-
needs_i8_conversion, is_datetimelike_v_numeric, is_integer_dtype)
20+
needs_i8_conversion, is_datetimelike_v_numeric,
21+
is_integer_dtype, is_categorical_dtype, is_object_dtype,
22+
is_timedelta64_dtype, is_datetime64_dtype, is_bool_dtype)
2123

2224
# -----------------------------------------------------------------------------
2325
# Functions that add arithmetic methods to objects, given arithmetic factory
@@ -276,11 +278,11 @@ def __init__(self, left, right, name):
276278
lvalues = self._convert_to_array(left, name=name)
277279
rvalues = self._convert_to_array(right, name=name, other=lvalues)
278280

279-
self.is_timedelta_lhs = com.is_timedelta64_dtype(left)
280-
self.is_datetime_lhs = com.is_datetime64_dtype(left)
281+
self.is_timedelta_lhs = is_timedelta64_dtype(left)
282+
self.is_datetime_lhs = is_datetime64_dtype(left)
281283
self.is_integer_lhs = left.dtype.kind in ['i', 'u']
282-
self.is_datetime_rhs = com.is_datetime64_dtype(rvalues)
283-
self.is_timedelta_rhs = com.is_timedelta64_dtype(rvalues)
284+
self.is_datetime_rhs = is_datetime64_dtype(rvalues)
285+
self.is_timedelta_rhs = is_timedelta64_dtype(rvalues)
284286
self.is_integer_rhs = rvalues.dtype.kind in ('i', 'u')
285287

286288
self._validate()
@@ -355,7 +357,7 @@ def _convert_to_array(self, values, name=None, other=None):
355357
elif isinstance(values, pd.DatetimeIndex):
356358
values = values.to_series()
357359
elif not (isinstance(values, (np.ndarray, pd.Series)) and
358-
com.is_datetime64_dtype(values)):
360+
is_datetime64_dtype(values)):
359361
values = tslib.array_to_datetime(values)
360362
elif inferred_type in ('timedelta', 'timedelta64'):
361363
# have a timedelta, convert to to ns here
@@ -448,8 +450,8 @@ def maybe_convert_for_time_op(cls, left, right, name):
448450
that the data is not the right type for time ops.
449451
"""
450452
# decide if we can do it
451-
is_timedelta_lhs = com.is_timedelta64_dtype(left)
452-
is_datetime_lhs = com.is_datetime64_dtype(left)
453+
is_timedelta_lhs = is_timedelta64_dtype(left)
454+
is_datetime_lhs = is_datetime64_dtype(left)
453455
if not (is_datetime_lhs or is_timedelta_lhs):
454456
return None
455457

@@ -547,17 +549,17 @@ def na_op(x, y):
547549

548550
# dispatch to the categorical if we have a categorical
549551
# in either operand
550-
if com.is_categorical_dtype(x):
552+
if is_categorical_dtype(x):
551553
return op(x,y)
552-
elif com.is_categorical_dtype(y) and not lib.isscalar(y):
554+
elif is_categorical_dtype(y) and not isscalar(y):
553555
return op(y,x)
554556

555-
if com.is_object_dtype(x.dtype):
557+
if is_object_dtype(x.dtype):
556558
if isinstance(y, list):
557559
y = lib.list_to_object_array(y)
558560

559561
if isinstance(y, (np.ndarray, pd.Series)):
560-
if not com.is_object_dtype(y.dtype):
562+
if not is_object_dtype(y.dtype):
561563
result = lib.vec_compare(x, y.astype(np.object_), op)
562564
else:
563565
result = lib.vec_compare(x, y, op)
@@ -574,7 +576,7 @@ def na_op(x, y):
574576
raise TypeError("invalid type comparison")
575577

576578
# numpy does not like comparisons vs None
577-
if lib.isscalar(y) and isnull(y):
579+
if isscalar(y) and isnull(y):
578580
y = np.nan
579581

580582
# we have a datetime/timedelta and may need to convert
@@ -624,13 +626,13 @@ def wrapper(self, other, axis=None):
624626
return self._constructor(na_op(self.values, np.asarray(other)),
625627
index=self.index).__finalize__(self)
626628
elif isinstance(other, pd.Categorical):
627-
if not com.is_categorical_dtype(self):
629+
if not is_categorical_dtype(self):
628630
msg = "Cannot compare a Categorical for op {op} with Series of dtype {typ}.\n"\
629631
"If you want to compare values, use 'series <op> np.asarray(other)'."
630632
raise TypeError(msg.format(op=op,typ=self.dtype))
631633

632634

633-
if com.is_categorical_dtype(self):
635+
if is_categorical_dtype(self):
634636
# cats are a special case as get_values() would return an ndarray, which would then
635637
# not take categories ordering into account
636638
# we can go directly to op, as the na_op would just test again and dispatch to it.
@@ -641,7 +643,7 @@ def wrapper(self, other, axis=None):
641643
other = np.asarray(other)
642644

643645
res = na_op(values, other)
644-
if lib.isscalar(res):
646+
if isscalar(res):
645647
raise TypeError('Could not compare %s type with Series'
646648
% type(other))
647649

@@ -667,7 +669,7 @@ def na_op(x, y):
667669
y = lib.list_to_object_array(y)
668670

669671
if isinstance(y, (np.ndarray, pd.Series)):
670-
if (com.is_bool_dtype(x.dtype) and com.is_bool_dtype(y.dtype)):
672+
if (is_bool_dtype(x.dtype) and is_bool_dtype(y.dtype)):
671673
result = op(x, y) # when would this be hit?
672674
else:
673675
x = com._ensure_object(x)
@@ -1069,7 +1071,7 @@ def na_op(x, y):
10691071

10701072
# work only for scalars
10711073
def f(self, other):
1072-
if not lib.isscalar(other):
1074+
if not isscalar(other):
10731075
raise ValueError('Simple arithmetic with %s can only be '
10741076
'done with scalar values' %
10751077
self._constructor.__name__)

0 commit comments

Comments
 (0)