Skip to content

Commit 77883ef

Browse files
committed
changes
1 parent 1537d37 commit 77883ef

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
is_int64_dtype, is_integer, is_scalar, is_timedelta64_dtype)
1616
from pandas.core.dtypes.generic import (
@@ -318,7 +318,7 @@ def has_duplicates(self):
318318
def __contains__(self, key):
319319
hash(key)
320320
try:
321-
key = com.ensure_python_int(key)
321+
key = cast.ensure_python_int(key)
322322
except TypeError:
323323
return False
324324
return key in self._range
@@ -681,12 +681,12 @@ def __floordiv__(self, other):
681681
start, start + 1, 1, name=self.name)
682682
return self._int64index // other
683683

684-
def all(self) -> bool:
684+
def all(self):
685685
if 0 in self._range:
686686
return False
687687
return True
688688

689-
def any(self) -> bool:
689+
def any(self):
690690
return any(self._range)
691691

692692
@classmethod

0 commit comments

Comments
 (0)