Skip to content

Commit dca809b

Browse files
authored
CLN: Remove long and integer_types from pandas.compat (#25862)
1 parent 72f4098 commit dca809b

29 files changed

+86
-127
lines changed

pandas/compat/__init__.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
Key items to import for 2/3 compatible code:
88
* iterators: reduce()
99
* lists: lrange(), lmap(), lzip(), lfilter()
10-
* longs: long (int in Python 3)
1110
* iterable method compatibility: iteritems, iterkeys, itervalues
1211
* Uses the original method if available, otherwise uses items, keys, values.
1312
* types:
@@ -108,7 +107,6 @@ def get_range_parameters(data):
108107
# have to explicitly put builtins into the namespace
109108
intern = sys.intern
110109
reduce = functools.reduce
111-
long = int
112110
unichr = chr
113111

114112
# list-producing versions of the major Python iterating functions
@@ -172,7 +170,6 @@ def get_range_parameters(data):
172170
# import iterator versions of these functions
173171
intern = intern
174172
reduce = reduce
175-
long = long
176173
unichr = unichr
177174

178175
# Python 2-builtin ranges produce lists
@@ -250,7 +247,6 @@ class to receive bound method
250247

251248
if PY3:
252249
string_types = str,
253-
integer_types = int,
254250
class_types = type,
255251
text_type = str
256252
binary_type = bytes
@@ -293,7 +289,6 @@ def set_function_name(f, name, cls):
293289
return f
294290
else:
295291
string_types = basestring,
296-
integer_types = (int, long)
297292
class_types = (type, types.ClassType)
298293
text_type = unicode
299294
binary_type = str

pandas/core/internals/blocks.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1959,9 +1959,9 @@ def _can_hold_element(self, element):
19591959
not issubclass(tipo.type, (np.datetime64, np.timedelta64)))
19601960
return (
19611961
isinstance(
1962-
element, (float, int, np.floating, np.int_, compat.long))
1963-
and not isinstance(element, (bool, np.bool_, datetime, timedelta,
1964-
np.datetime64, np.timedelta64)))
1962+
element, (float, int, np.floating, np.int_)) and
1963+
not isinstance(element, (bool, np.bool_, datetime, timedelta,
1964+
np.datetime64, np.timedelta64)))
19651965

19661966
def to_native_types(self, slicer=None, na_rep='', float_format=None,
19671967
decimal='.', quoting=None, **kwargs):
@@ -2011,8 +2011,8 @@ def _can_hold_element(self, element):
20112011
return (
20122012
isinstance(
20132013
element,
2014-
(float, int, complex, np.float_, np.int_, compat.long))
2015-
and not isinstance(element, (bool, np.bool_)))
2014+
(float, int, complex, np.float_, np.int_)) and
2015+
not isinstance(element, (bool, np.bool_)))
20162016

20172017
def should_store(self, value):
20182018
return issubclass(value.dtype.type, np.complexfloating)

pandas/core/sorting.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from pandas._libs import algos, hashtable, lib
77
from pandas._libs.hashtable import unique_label_indices
8-
from pandas.compat import PY3, long, string_types
8+
from pandas.compat import PY3, string_types
99

1010
from pandas.core.dtypes.cast import infer_dtype_from_array
1111
from pandas.core.dtypes.common import (
@@ -45,9 +45,9 @@ def get_group_index(labels, shape, sort, xnull):
4545
labels are equal at all location.
4646
"""
4747
def _int64_cut_off(shape):
48-
acc = long(1)
48+
acc = 1
4949
for i, mul in enumerate(shape):
50-
acc *= long(mul)
50+
acc *= int(mul)
5151
if not acc < _INT64_MAX:
5252
return i
5353
return len(shape)
@@ -122,9 +122,9 @@ def get_compressed_ids(labels, sizes):
122122

123123

124124
def is_int64_overflow_possible(shape):
125-
the_prod = long(1)
125+
the_prod = 1
126126
for x in shape:
127-
the_prod *= long(x)
127+
the_prod *= int(x)
128128

129129
return the_prod >= _INT64_MAX
130130

pandas/io/json/json.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import pandas._libs.json as json
88
from pandas._libs.tslibs import iNaT
9-
from pandas.compat import StringIO, long, to_str
9+
from pandas.compat import StringIO, to_str
1010
from pandas.errors import AbstractMethodError
1111

1212
from pandas.core.dtypes.common import is_period_dtype
@@ -619,10 +619,10 @@ class Parser(object):
619619

620620
_STAMP_UNITS = ('s', 'ms', 'us', 'ns')
621621
_MIN_STAMPS = {
622-
's': long(31536000),
623-
'ms': long(31536000000),
624-
'us': long(31536000000000),
625-
'ns': long(31536000000000000)}
622+
's': 31536000,
623+
'ms': 31536000000,
624+
'us': 31536000000000,
625+
'ns': 31536000000000000}
626626

627627
def __init__(self, json, orient, dtype=None, convert_axes=True,
628628
convert_dates=True, keep_default_dates=False, numpy=False,

pandas/io/stata.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -765,9 +765,9 @@ class StataMissingValue(StringMixin):
765765
bases = (101, 32741, 2147483621)
766766
for b in bases:
767767
# Conversion to long to avoid hash issues on 32 bit platforms #8968
768-
MISSING_VALUES[compat.long(b)] = '.'
768+
MISSING_VALUES[b] = '.'
769769
for i in range(1, 27):
770-
MISSING_VALUES[compat.long(i + b)] = '.' + chr(96 + i)
770+
MISSING_VALUES[i + b] = '.' + chr(96 + i)
771771

772772
float32_base = b'\x00\x00\x00\x7f'
773773
increment = struct.unpack('<i', b'\x00\x08\x00\x00')[0]
@@ -798,8 +798,8 @@ class StataMissingValue(StringMixin):
798798

799799
def __init__(self, value):
800800
self._value = value
801-
# Conversion to long to avoid hash issues on 32 bit platforms #8968
802-
value = compat.long(value) if value < 2147483648 else float(value)
801+
# Conversion to int to avoid hash issues on 32 bit platforms #8968
802+
value = int(value) if value < 2147483648 else float(value)
803803
self._str = self.MISSING_VALUES[value]
804804

805805
string = property(lambda self: self._str,

pandas/tests/arithmetic/conftest.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
import numpy as np
33
import pytest
44

5-
from pandas.compat import long
6-
75
import pandas as pd
86
import pandas.util.testing as tm
97

@@ -32,7 +30,7 @@ def one(request):
3230
for dtype in [np.int64, np.uint64, np.float64]]
3331
zeros.extend([np.array(0, dtype=dtype)
3432
for dtype in [np.int64, np.uint64, np.float64]])
35-
zeros.extend([0, 0.0, long(0)])
33+
zeros.extend([0, 0.0])
3634

3735

3836
@pytest.fixture(params=zeros)

pandas/tests/arithmetic/test_period.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ def test_pi_add_iadd_int(self, one):
674674
def test_pi_sub_isub_int(self, one):
675675
"""
676676
PeriodIndex.__sub__ and __isub__ with several representations of
677-
the integer 1, e.g. int, long, np.int64, np.uint8, ...
677+
the integer 1, e.g. int, np.int64, np.uint8, ...
678678
"""
679679
rng = pd.period_range('2000-01-01 09:00', freq='H', periods=10)
680680
result = rng - one

pandas/tests/arrays/categorical/test_dtypes.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
import numpy as np
33
import pytest
44

5-
from pandas.compat import long
6-
75
from pandas.core.dtypes.dtypes import CategoricalDtype
86

97
from pandas import Categorical, CategoricalIndex, Index, Series, Timestamp
@@ -165,10 +163,9 @@ def test_astype_category(self, dtype_ordered, cat_ordered):
165163

166164
def test_iter_python_types(self):
167165
# GH-19909
168-
# TODO(Py2): Remove long
169166
cat = Categorical([1, 2])
170-
assert isinstance(list(cat)[0], (int, long))
171-
assert isinstance(cat.tolist()[0], (int, long))
167+
assert isinstance(list(cat)[0], int)
168+
assert isinstance(cat.tolist()[0], int)
172169

173170
def test_iter_python_types_datetime(self):
174171
cat = Categorical([Timestamp('2017-01-01'),

pandas/tests/arrays/test_datetimelike.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
import numpy as np
33
import pytest
44

5-
import pandas.compat as compat
6-
75
import pandas as pd
86
from pandas.core.arrays import DatetimeArray, PeriodArray, TimedeltaArray
97
import pandas.util.testing as tm
@@ -133,10 +131,10 @@ def test_unbox_scalar(self):
133131
data = np.arange(10, dtype='i8') * 24 * 3600 * 10**9
134132
arr = self.array_cls(data, freq='D')
135133
result = arr._unbox_scalar(arr[0])
136-
assert isinstance(result, (int, compat.long))
134+
assert isinstance(result, int)
137135

138136
result = arr._unbox_scalar(pd.NaT)
139-
assert isinstance(result, (int, compat.long))
137+
assert isinstance(result, int)
140138

141139
with pytest.raises(ValueError):
142140
arr._unbox_scalar('foo')

pandas/tests/arrays/test_integer.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,6 @@ def test_conversions(data_missing):
509509
if pd.isnull(r):
510510
assert pd.isnull(e)
511511
elif is_integer(r):
512-
# PY2 can be int or long
513512
assert r == e
514513
assert is_integer(e)
515514
else:

0 commit comments

Comments
 (0)