Skip to content

Commit ab94b7f

Browse files
committed
changes
1 parent d2de94e commit ab94b7f

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

pandas/core/common.py

-10
Original file line numberDiff line numberDiff line change
@@ -490,13 +490,3 @@ def f(x):
490490
f = mapper
491491

492492
return f
493-
494-
495-
def ensure_python_int(value: Union[int, Any]) -> int:
496-
msg = "Wrong type {} for value {}"
497-
try:
498-
new_value = int(value)
499-
assert (new_value == value)
500-
except (TypeError, ValueError, AssertionError):
501-
raise TypeError(msg.format(type(value), value))
502-
return new_value

pandas/core/dtypes/cast.py

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

33
from datetime import datetime, timedelta
4+
from typing import Any, Union
45

56
import numpy as np
67

@@ -1333,3 +1334,13 @@ def maybe_cast_to_integer_array(arr, dtype, copy=False):
13331334
if is_integer_dtype(dtype) and (is_float_dtype(arr) or
13341335
is_object_dtype(arr)):
13351336
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/indexes/range.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
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 concat as _concat
13+
from pandas.core.dtypes import cast, concat as _concat
1414
from pandas.core.dtypes.common import (
1515
ensure_python_int, is_int64_dtype, is_integer, is_scalar,
1616
is_timedelta64_dtype)
@@ -337,7 +337,7 @@ def has_duplicates(self):
337337
def __contains__(self, key):
338338
hash(key)
339339
try:
340-
key = com.ensure_python_int(key)
340+
key = cast.ensure_python_int(key)
341341
except TypeError:
342342
return False
343343
return key in self._range
@@ -648,12 +648,12 @@ def __floordiv__(self, other):
648648
return self._simple_new(start, start + 1, 1, name=self.name)
649649
return self._int64index // other
650650

651-
def all(self) -> bool:
651+
def all(self):
652652
if 0 in self._range:
653653
return False
654654
return True
655655

656-
def any(self) -> bool:
656+
def any(self):
657657
return any(self._range)
658658

659659
@classmethod

0 commit comments

Comments
 (0)