Skip to content

Commit fa4c649

Browse files
committed
Changes to .all()
1 parent 77883ef commit fa4c649

File tree

3 files changed

+31
-17
lines changed

3 files changed

+31
-17
lines changed

pandas/core/dtypes/cast.py

-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
""" routings for casting """
22

33
from datetime import datetime, timedelta
4-
from typing import Any, Union
54

65
import numpy as np
76

@@ -1334,13 +1333,3 @@ def maybe_cast_to_integer_array(arr, dtype, copy=False):
13341333
if is_integer_dtype(dtype) and (is_float_dtype(arr) or
13351334
is_object_dtype(arr)):
13361335
raise ValueError("Trying to coerce float values to integers")
1337-
1338-
1339-
def ensure_python_int(value: Union[int, Any]) -> int:
1340-
msg = "Wrong type {} for value {}"
1341-
try:
1342-
new_value = int(value)
1343-
assert (new_value == value)
1344-
except (TypeError, ValueError, AssertionError):
1345-
raise TypeError(msg.format(type(value), value))
1346-
return new_value

pandas/core/dtypes/common.py

+26
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
""" common type operations """
2+
from typing import Union
23
import warnings
34

45
import numpy as np
@@ -125,6 +126,31 @@ def ensure_int_or_float(arr: ArrayLike, copy=False) -> np.array:
125126
return arr.astype('float64', copy=copy)
126127

127128

129+
def ensure_python_int(value: Union[int, np.integer]) -> int:
130+
"""
131+
Ensure that a value is a python int.
132+
133+
Parameters
134+
----------
135+
value: int or numpy.integer
136+
137+
Returns
138+
-------
139+
int
140+
141+
Raises
142+
------
143+
TypeError: if the value isn't an int or can't be converted to one.
144+
"""
145+
msg = "Wrong type {} for value {}"
146+
try:
147+
new_value = int(value)
148+
assert (new_value == value)
149+
except (TypeError, ValueError, AssertionError):
150+
raise TypeError(msg.format(type(value), value))
151+
return new_value
152+
153+
128154
def classes(*klasses):
129155
""" evaluate if the tipo is a subclass of the klasses """
130156
return lambda tipo: issubclass(tipo, klasses)

pandas/core/indexes/range.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
from pandas.compat.numpy import function as nv
1111
from pandas.util._decorators import Appender, cache_readonly
1212

13-
from pandas.core.dtypes import cast, concat as _concat
13+
from pandas.core.dtypes import concat as _concat
1414
from pandas.core.dtypes.common import (
15-
is_int64_dtype, is_integer, is_scalar, is_timedelta64_dtype)
15+
ensure_python_int, is_int64_dtype, is_integer, is_scalar,
16+
is_timedelta64_dtype)
1617
from pandas.core.dtypes.generic import (
1718
ABCDataFrame, ABCSeries, ABCTimedeltaIndex)
1819

@@ -318,7 +319,7 @@ def has_duplicates(self):
318319
def __contains__(self, key):
319320
hash(key)
320321
try:
321-
key = cast.ensure_python_int(key)
322+
key = ensure_python_int(key)
322323
except TypeError:
323324
return False
324325
return key in self._range
@@ -682,9 +683,7 @@ def __floordiv__(self, other):
682683
return self._int64index // other
683684

684685
def all(self):
685-
if 0 in self._range:
686-
return False
687-
return True
686+
return 0 not in self._range
688687

689688
def any(self):
690689
return any(self._range)

0 commit comments

Comments
 (0)