Skip to content

Commit 4826efc

Browse files
committed
changes
1 parent cfd68e5 commit 4826efc

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
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

+2-2
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

0 commit comments

Comments
 (0)