Skip to content

CLN: rename lib.isscalar to lib.is_scalar #19000

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pandas/_libs/lib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def memory_usage_of_objects(ndarray[object, ndim=1] arr):
# ----------------------------------------------------------------------


cpdef bint isscalar(object val):
cpdef bint is_scalar(object val):
"""
Return True if given value is scalar.

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ def _broadcast(arr_or_scalar, shape):
Helper function to broadcast arrays / scalars to the desired shape.
"""
if _np_version_under1p10:
if lib.isscalar(arr_or_scalar):
if is_scalar(arr_or_scalar):
out = np.empty(shape)
out.fill(arr_or_scalar)
else:
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/computation/align.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def _align(terms):
return np.result_type(terms.type), None

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

# perform the main alignment
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/computation/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,11 +368,11 @@ def _maybe_transform_eq_ne(self, node, left=None, right=None):

def _maybe_downcast_constants(self, left, right):
f32 = np.dtype(np.float32)
if left.isscalar and not right.isscalar and right.return_type == f32:
if left.is_scalar and not right.is_scalar and right.return_type == f32:
# right is a float32 array, left is a scalar
name = self.env.add_tmp(np.float32(left.value))
left = self.term_type(name, self.env)
if right.isscalar and not left.isscalar and left.return_type == f32:
if right.is_scalar and not left.is_scalar and left.return_type == f32:
# left is a float32 array, right is a scalar
name = self.env.add_tmp(np.float32(right.value))
right = self.term_type(name, self.env)
Expand Down
12 changes: 6 additions & 6 deletions pandas/core/computation/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def update(self, value):
self.value = value

@property
def isscalar(self):
def is_scalar(self):
return is_scalar(self._value)

@property
Expand Down Expand Up @@ -214,8 +214,8 @@ def operand_types(self):
return frozenset(term.type for term in com.flatten(self))

@property
def isscalar(self):
return all(operand.isscalar for operand in self.operands)
def is_scalar(self):
return all(operand.is_scalar for operand in self.operands)

@property
def is_datetime(self):
Expand Down Expand Up @@ -412,7 +412,7 @@ def stringify(value):

lhs, rhs = self.lhs, self.rhs

if is_term(lhs) and lhs.is_datetime and is_term(rhs) and rhs.isscalar:
if is_term(lhs) and lhs.is_datetime and is_term(rhs) and rhs.is_scalar:
v = rhs.value
if isinstance(v, (int, float)):
v = stringify(v)
Expand All @@ -421,7 +421,7 @@ def stringify(value):
v = v.tz_convert('UTC')
self.rhs.update(v)

if is_term(rhs) and rhs.is_datetime and is_term(lhs) and lhs.isscalar:
if is_term(rhs) and rhs.is_datetime and is_term(lhs) and lhs.is_scalar:
v = lhs.value
if isinstance(v, (int, float)):
v = stringify(v)
Expand All @@ -431,7 +431,7 @@ def stringify(value):
self.lhs.update(v)

def _disallow_scalar_only_bool_ops(self):
if ((self.lhs.isscalar or self.rhs.isscalar) and
if ((self.lhs.is_scalar or self.rhs.is_scalar) and
self.op in _bool_ops_dict and
(not (issubclass(self.rhs.return_type, (bool, np.bool_)) and
issubclass(self.lhs.return_type, (bool, np.bool_))))):
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/dtypes/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

is_complex = lib.is_complex

is_scalar = lib.isscalar
is_scalar = lib.is_scalar

is_decimal = lib.is_decimal

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,7 @@ def _convert_for_op(self, value):

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

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@ def astype(self, dtype, copy=True):

def _ensure_datetimelike_to_i8(other):
""" helper for coercing an input scalar or array to i8 """
if lib.isscalar(other) and isna(other):
if is_scalar(other) and isna(other):
other = iNaT
elif isinstance(other, ABCIndexClass):
# convert tz if needed
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __new__(cls, data=None, dtype=None, copy=False, name=None,
if fastpath:
return cls._simple_new(data, name=name)

# isscalar, generators handled in coerce_to_ndarray
# is_scalar, generators handled in coerce_to_ndarray
data = cls._coerce_to_ndarray(data)

if issubclass(data.dtype.type, compat.string_types):
Expand Down
16 changes: 8 additions & 8 deletions pandas/tests/dtypes/test_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -1098,9 +1098,9 @@ def test_is_timedelta(self):
assert not is_timedelta64_ns_dtype(tdi.astype('timedelta64[h]'))


class Testisscalar(object):
class TestIsScalar(object):

def test_isscalar_builtin_scalars(self):
def test_is_scalar_builtin_scalars(self):
assert is_scalar(None)
assert is_scalar(True)
assert is_scalar(False)
Expand All @@ -1115,7 +1115,7 @@ def test_isscalar_builtin_scalars(self):
assert is_scalar(timedelta(hours=1))
assert is_scalar(pd.NaT)

def test_isscalar_builtin_nonscalars(self):
def test_is_scalar_builtin_nonscalars(self):
assert not is_scalar({})
assert not is_scalar([])
assert not is_scalar([1])
Expand All @@ -1124,7 +1124,7 @@ def test_isscalar_builtin_nonscalars(self):
assert not is_scalar(slice(None))
assert not is_scalar(Ellipsis)

def test_isscalar_numpy_array_scalars(self):
def test_is_scalar_numpy_array_scalars(self):
assert is_scalar(np.int64(1))
assert is_scalar(np.float64(1.))
assert is_scalar(np.int32(1))
Expand All @@ -1135,27 +1135,27 @@ def test_isscalar_numpy_array_scalars(self):
assert is_scalar(np.datetime64('2014-01-01'))
assert is_scalar(np.timedelta64(1, 'h'))

def test_isscalar_numpy_zerodim_arrays(self):
def test_is_scalar_numpy_zerodim_arrays(self):
for zerodim in [np.array(1), np.array('foobar'),
np.array(np.datetime64('2014-01-01')),
np.array(np.timedelta64(1, 'h')),
np.array(np.datetime64('NaT'))]:
assert not is_scalar(zerodim)
assert is_scalar(lib.item_from_zerodim(zerodim))

def test_isscalar_numpy_arrays(self):
def test_is_scalar_numpy_arrays(self):
assert not is_scalar(np.array([]))
assert not is_scalar(np.array([[]]))
assert not is_scalar(np.matrix('1; 2'))

def test_isscalar_pandas_scalars(self):
def test_is_scalar_pandas_scalars(self):
assert is_scalar(Timestamp('2014-01-01'))
assert is_scalar(Timedelta(hours=1))
assert is_scalar(Period('2014-01-01'))
assert is_scalar(Interval(left=0, right=1))
assert is_scalar(DateOffset(days=1))

def test_lisscalar_pandas_containers(self):
def test_is_scalar_pandas_containers(self):
assert not is_scalar(Series())
assert not is_scalar(Series([1]))
assert not is_scalar(DataFrame())
Expand Down