Skip to content

Commit 461221d

Browse files
databasedavjreback
authored andcommitted
CLN: rename lib.isscalar to lib.is_scalar (pandas-dev#19000)
1 parent e957dcd commit 461221d

File tree

10 files changed

+23
-23
lines changed

10 files changed

+23
-23
lines changed

pandas/_libs/lib.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def memory_usage_of_objects(ndarray[object, ndim=1] arr):
9898
# ----------------------------------------------------------------------
9999

100100

101-
cpdef bint isscalar(object val):
101+
cpdef bint is_scalar(object val):
102102
"""
103103
Return True if given value is scalar.
104104

pandas/core/algorithms.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ def _broadcast(arr_or_scalar, shape):
750750
Helper function to broadcast arrays / scalars to the desired shape.
751751
"""
752752
if _np_version_under1p10:
753-
if lib.isscalar(arr_or_scalar):
753+
if is_scalar(arr_or_scalar):
754754
out = np.empty(shape)
755755
out.fill(arr_or_scalar)
756756
else:

pandas/core/computation/align.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def _align(terms):
126126
return np.result_type(terms.type), None
127127

128128
# if all resolved variables are numeric scalars
129-
if all(term.isscalar for term in terms):
129+
if all(term.is_scalar for term in terms):
130130
return _result_type_many(*(term.value for term in terms)).type, None
131131

132132
# perform the main alignment

pandas/core/computation/expr.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -368,11 +368,11 @@ def _maybe_transform_eq_ne(self, node, left=None, right=None):
368368

369369
def _maybe_downcast_constants(self, left, right):
370370
f32 = np.dtype(np.float32)
371-
if left.isscalar and not right.isscalar and right.return_type == f32:
371+
if left.is_scalar and not right.is_scalar and right.return_type == f32:
372372
# right is a float32 array, left is a scalar
373373
name = self.env.add_tmp(np.float32(left.value))
374374
left = self.term_type(name, self.env)
375-
if right.isscalar and not left.isscalar and left.return_type == f32:
375+
if right.is_scalar and not left.is_scalar and left.return_type == f32:
376376
# left is a float32 array, right is a scalar
377377
name = self.env.add_tmp(np.float32(right.value))
378378
right = self.term_type(name, self.env)

pandas/core/computation/ops.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def update(self, value):
9999
self.value = value
100100

101101
@property
102-
def isscalar(self):
102+
def is_scalar(self):
103103
return is_scalar(self._value)
104104

105105
@property
@@ -214,8 +214,8 @@ def operand_types(self):
214214
return frozenset(term.type for term in com.flatten(self))
215215

216216
@property
217-
def isscalar(self):
218-
return all(operand.isscalar for operand in self.operands)
217+
def is_scalar(self):
218+
return all(operand.is_scalar for operand in self.operands)
219219

220220
@property
221221
def is_datetime(self):
@@ -412,7 +412,7 @@ def stringify(value):
412412

413413
lhs, rhs = self.lhs, self.rhs
414414

415-
if is_term(lhs) and lhs.is_datetime and is_term(rhs) and rhs.isscalar:
415+
if is_term(lhs) and lhs.is_datetime and is_term(rhs) and rhs.is_scalar:
416416
v = rhs.value
417417
if isinstance(v, (int, float)):
418418
v = stringify(v)
@@ -421,7 +421,7 @@ def stringify(value):
421421
v = v.tz_convert('UTC')
422422
self.rhs.update(v)
423423

424-
if is_term(rhs) and rhs.is_datetime and is_term(lhs) and lhs.isscalar:
424+
if is_term(rhs) and rhs.is_datetime and is_term(lhs) and lhs.is_scalar:
425425
v = lhs.value
426426
if isinstance(v, (int, float)):
427427
v = stringify(v)
@@ -431,7 +431,7 @@ def stringify(value):
431431
self.lhs.update(v)
432432

433433
def _disallow_scalar_only_bool_ops(self):
434-
if ((self.lhs.isscalar or self.rhs.isscalar) and
434+
if ((self.lhs.is_scalar or self.rhs.is_scalar) and
435435
self.op in _bool_ops_dict and
436436
(not (issubclass(self.rhs.return_type, (bool, np.bool_)) and
437437
issubclass(self.lhs.return_type, (bool, np.bool_))))):

pandas/core/dtypes/inference.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
is_complex = lib.is_complex
1919

20-
is_scalar = lib.isscalar
20+
is_scalar = lib.is_scalar
2121

2222
is_decimal = lib.is_decimal
2323

pandas/core/indexes/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1101,7 +1101,7 @@ def _convert_for_op(self, value):
11011101

11021102
def _assert_can_do_op(self, value):
11031103
""" Check value is valid for scalar op """
1104-
if not lib.isscalar(value):
1104+
if not is_scalar(value):
11051105
msg = "'value' must be a scalar, passed: {0}"
11061106
raise TypeError(msg.format(type(value).__name__))
11071107

pandas/core/indexes/datetimelike.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ def astype(self, dtype, copy=True):
905905

906906
def _ensure_datetimelike_to_i8(other):
907907
""" helper for coercing an input scalar or array to i8 """
908-
if lib.isscalar(other) and isna(other):
908+
if is_scalar(other) and isna(other):
909909
other = iNaT
910910
elif isinstance(other, ABCIndexClass):
911911
# convert tz if needed

pandas/core/indexes/numeric.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def __new__(cls, data=None, dtype=None, copy=False, name=None,
3838
if fastpath:
3939
return cls._simple_new(data, name=name)
4040

41-
# isscalar, generators handled in coerce_to_ndarray
41+
# is_scalar, generators handled in coerce_to_ndarray
4242
data = cls._coerce_to_ndarray(data)
4343

4444
if issubclass(data.dtype.type, compat.string_types):

pandas/tests/dtypes/test_inference.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -1098,9 +1098,9 @@ def test_is_timedelta(self):
10981098
assert not is_timedelta64_ns_dtype(tdi.astype('timedelta64[h]'))
10991099

11001100

1101-
class Testisscalar(object):
1101+
class TestIsScalar(object):
11021102

1103-
def test_isscalar_builtin_scalars(self):
1103+
def test_is_scalar_builtin_scalars(self):
11041104
assert is_scalar(None)
11051105
assert is_scalar(True)
11061106
assert is_scalar(False)
@@ -1115,7 +1115,7 @@ def test_isscalar_builtin_scalars(self):
11151115
assert is_scalar(timedelta(hours=1))
11161116
assert is_scalar(pd.NaT)
11171117

1118-
def test_isscalar_builtin_nonscalars(self):
1118+
def test_is_scalar_builtin_nonscalars(self):
11191119
assert not is_scalar({})
11201120
assert not is_scalar([])
11211121
assert not is_scalar([1])
@@ -1124,7 +1124,7 @@ def test_isscalar_builtin_nonscalars(self):
11241124
assert not is_scalar(slice(None))
11251125
assert not is_scalar(Ellipsis)
11261126

1127-
def test_isscalar_numpy_array_scalars(self):
1127+
def test_is_scalar_numpy_array_scalars(self):
11281128
assert is_scalar(np.int64(1))
11291129
assert is_scalar(np.float64(1.))
11301130
assert is_scalar(np.int32(1))
@@ -1135,27 +1135,27 @@ def test_isscalar_numpy_array_scalars(self):
11351135
assert is_scalar(np.datetime64('2014-01-01'))
11361136
assert is_scalar(np.timedelta64(1, 'h'))
11371137

1138-
def test_isscalar_numpy_zerodim_arrays(self):
1138+
def test_is_scalar_numpy_zerodim_arrays(self):
11391139
for zerodim in [np.array(1), np.array('foobar'),
11401140
np.array(np.datetime64('2014-01-01')),
11411141
np.array(np.timedelta64(1, 'h')),
11421142
np.array(np.datetime64('NaT'))]:
11431143
assert not is_scalar(zerodim)
11441144
assert is_scalar(lib.item_from_zerodim(zerodim))
11451145

1146-
def test_isscalar_numpy_arrays(self):
1146+
def test_is_scalar_numpy_arrays(self):
11471147
assert not is_scalar(np.array([]))
11481148
assert not is_scalar(np.array([[]]))
11491149
assert not is_scalar(np.matrix('1; 2'))
11501150

1151-
def test_isscalar_pandas_scalars(self):
1151+
def test_is_scalar_pandas_scalars(self):
11521152
assert is_scalar(Timestamp('2014-01-01'))
11531153
assert is_scalar(Timedelta(hours=1))
11541154
assert is_scalar(Period('2014-01-01'))
11551155
assert is_scalar(Interval(left=0, right=1))
11561156
assert is_scalar(DateOffset(days=1))
11571157

1158-
def test_lisscalar_pandas_containers(self):
1158+
def test_is_scalar_pandas_containers(self):
11591159
assert not is_scalar(Series())
11601160
assert not is_scalar(Series([1]))
11611161
assert not is_scalar(DataFrame())

0 commit comments

Comments
 (0)