Skip to content

CLN: Remove long and integer_types from pandas.compat #25862

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions pandas/compat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
Key items to import for 2/3 compatible code:
* iterators: reduce()
* lists: lrange(), lmap(), lzip(), lfilter()
* longs: long (int in Python 3)
* iterable method compatibility: iteritems, iterkeys, itervalues
* Uses the original method if available, otherwise uses items, keys, values.
* types:
Expand Down Expand Up @@ -108,7 +107,6 @@ def get_range_parameters(data):
# have to explicitly put builtins into the namespace
intern = sys.intern
reduce = functools.reduce
long = int
unichr = chr

# list-producing versions of the major Python iterating functions
Expand Down Expand Up @@ -172,7 +170,6 @@ def get_range_parameters(data):
# import iterator versions of these functions
intern = intern
reduce = reduce
long = long
unichr = unichr

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

if PY3:
string_types = str,
integer_types = int,
class_types = type,
text_type = str
binary_type = bytes
Expand Down Expand Up @@ -293,7 +289,6 @@ def set_function_name(f, name, cls):
return f
else:
string_types = basestring,
integer_types = (int, long)
class_types = (type, types.ClassType)
text_type = unicode
binary_type = str
Expand Down
10 changes: 5 additions & 5 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1959,9 +1959,9 @@ def _can_hold_element(self, element):
not issubclass(tipo.type, (np.datetime64, np.timedelta64)))
return (
isinstance(
element, (float, int, np.floating, np.int_, compat.long))
and not isinstance(element, (bool, np.bool_, datetime, timedelta,
np.datetime64, np.timedelta64)))
element, (float, int, np.floating, np.int_)) and
not isinstance(element, (bool, np.bool_, datetime, timedelta,
np.datetime64, np.timedelta64)))

def to_native_types(self, slicer=None, na_rep='', float_format=None,
decimal='.', quoting=None, **kwargs):
Expand Down Expand Up @@ -2011,8 +2011,8 @@ def _can_hold_element(self, element):
return (
isinstance(
element,
(float, int, complex, np.float_, np.int_, compat.long))
and not isinstance(element, (bool, np.bool_)))
(float, int, complex, np.float_, np.int_)) and
not isinstance(element, (bool, np.bool_)))

def should_store(self, value):
return issubclass(value.dtype.type, np.complexfloating)
Expand Down
10 changes: 5 additions & 5 deletions pandas/core/sorting.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from pandas._libs import algos, hashtable, lib
from pandas._libs.hashtable import unique_label_indices
from pandas.compat import PY3, long, string_types
from pandas.compat import PY3, string_types

from pandas.core.dtypes.cast import infer_dtype_from_array
from pandas.core.dtypes.common import (
Expand Down Expand Up @@ -45,9 +45,9 @@ def get_group_index(labels, shape, sort, xnull):
labels are equal at all location.
"""
def _int64_cut_off(shape):
acc = long(1)
acc = 1
for i, mul in enumerate(shape):
acc *= long(mul)
acc *= int(mul)
if not acc < _INT64_MAX:
return i
return len(shape)
Expand Down Expand Up @@ -122,9 +122,9 @@ def get_compressed_ids(labels, sizes):


def is_int64_overflow_possible(shape):
the_prod = long(1)
the_prod = 1
for x in shape:
the_prod *= long(x)
the_prod *= int(x)

return the_prod >= _INT64_MAX

Expand Down
10 changes: 5 additions & 5 deletions pandas/io/json/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import pandas._libs.json as json
from pandas._libs.tslibs import iNaT
from pandas.compat import StringIO, long, to_str
from pandas.compat import StringIO, to_str
from pandas.errors import AbstractMethodError

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

_STAMP_UNITS = ('s', 'ms', 'us', 'ns')
_MIN_STAMPS = {
's': long(31536000),
'ms': long(31536000000),
'us': long(31536000000000),
'ns': long(31536000000000000)}
's': 31536000,
'ms': 31536000000,
'us': 31536000000000,
'ns': 31536000000000000}

def __init__(self, json, orient, dtype=None, convert_axes=True,
convert_dates=True, keep_default_dates=False, numpy=False,
Expand Down
8 changes: 4 additions & 4 deletions pandas/io/stata.py
Original file line number Diff line number Diff line change
Expand Up @@ -765,9 +765,9 @@ class StataMissingValue(StringMixin):
bases = (101, 32741, 2147483621)
for b in bases:
# Conversion to long to avoid hash issues on 32 bit platforms #8968
MISSING_VALUES[compat.long(b)] = '.'
MISSING_VALUES[b] = '.'
for i in range(1, 27):
MISSING_VALUES[compat.long(i + b)] = '.' + chr(96 + i)
MISSING_VALUES[i + b] = '.' + chr(96 + i)

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

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

string = property(lambda self: self._str,
Expand Down
4 changes: 1 addition & 3 deletions pandas/tests/arithmetic/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
import numpy as np
import pytest

from pandas.compat import long

import pandas as pd
import pandas.util.testing as tm

Expand Down Expand Up @@ -32,7 +30,7 @@ def one(request):
for dtype in [np.int64, np.uint64, np.float64]]
zeros.extend([np.array(0, dtype=dtype)
for dtype in [np.int64, np.uint64, np.float64]])
zeros.extend([0, 0.0, long(0)])
zeros.extend([0, 0.0])


@pytest.fixture(params=zeros)
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/arithmetic/test_period.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ def test_pi_add_iadd_int(self, one):
def test_pi_sub_isub_int(self, one):
"""
PeriodIndex.__sub__ and __isub__ with several representations of
the integer 1, e.g. int, long, np.int64, np.uint8, ...
the integer 1, e.g. int, np.int64, np.uint8, ...
"""
rng = pd.period_range('2000-01-01 09:00', freq='H', periods=10)
result = rng - one
Expand Down
7 changes: 2 additions & 5 deletions pandas/tests/arrays/categorical/test_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
import numpy as np
import pytest

from pandas.compat import long

from pandas.core.dtypes.dtypes import CategoricalDtype

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

def test_iter_python_types(self):
# GH-19909
# TODO(Py2): Remove long
cat = Categorical([1, 2])
assert isinstance(list(cat)[0], (int, long))
assert isinstance(cat.tolist()[0], (int, long))
assert isinstance(list(cat)[0], int)
assert isinstance(cat.tolist()[0], int)

def test_iter_python_types_datetime(self):
cat = Categorical([Timestamp('2017-01-01'),
Expand Down
6 changes: 2 additions & 4 deletions pandas/tests/arrays/test_datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
import numpy as np
import pytest

import pandas.compat as compat

import pandas as pd
from pandas.core.arrays import DatetimeArray, PeriodArray, TimedeltaArray
import pandas.util.testing as tm
Expand Down Expand Up @@ -133,10 +131,10 @@ def test_unbox_scalar(self):
data = np.arange(10, dtype='i8') * 24 * 3600 * 10**9
arr = self.array_cls(data, freq='D')
result = arr._unbox_scalar(arr[0])
assert isinstance(result, (int, compat.long))
assert isinstance(result, int)

result = arr._unbox_scalar(pd.NaT)
assert isinstance(result, (int, compat.long))
assert isinstance(result, int)

with pytest.raises(ValueError):
arr._unbox_scalar('foo')
Expand Down
1 change: 0 additions & 1 deletion pandas/tests/arrays/test_integer.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,6 @@ def test_conversions(data_missing):
if pd.isnull(r):
assert pd.isnull(e)
elif is_integer(r):
# PY2 can be int or long
assert r == e
assert is_integer(e)
else:
Expand Down
6 changes: 3 additions & 3 deletions pandas/tests/frame/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import numpy as np
import pytest

from pandas.compat import long, lrange
from pandas.compat import lrange

import pandas as pd
from pandas import (
Expand Down Expand Up @@ -242,15 +242,15 @@ def test_itertuples(self, float_frame):
'ints': lrange(5)}, columns=['floats', 'ints'])

for tup in df.itertuples(index=False):
assert isinstance(tup[1], (int, long))
assert isinstance(tup[1], int)

df = self.klass(data={"a": [1, 2, 3], "b": [4, 5, 6]})
dfaa = df[['a', 'a']]

assert (list(dfaa.itertuples()) ==
[(0, 1, 1), (1, 2, 2), (2, 3, 3)])

# repr with be int/long on 32-bit/windows
# repr with int on 32-bit/windows
if not (compat.is_platform_windows() or compat.is_platform_32bit()):
assert (repr(list(df.itertuples(name=None))) ==
'[(0, 1, 4), (1, 2, 5), (2, 3, 6)]')
Expand Down
8 changes: 3 additions & 5 deletions pandas/tests/frame/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
import numpy.ma as ma
import pytest

from pandas.compat import (
PY36, is_platform_little_endian, lmap, long, lrange, lzip)
from pandas.compat import PY36, is_platform_little_endian, lmap, lrange, lzip

from pandas.core.dtypes.cast import construct_1d_object_array_from_listlike
from pandas.core.dtypes.common import is_integer_dtype
Expand Down Expand Up @@ -193,9 +192,8 @@ def test_constructor_overflow_int64(self):

# see gh-2355
data_scores = [(6311132704823138710, 273), (2685045978526272070, 23),
(8921811264899370420, 45),
(long(17019687244989530680), 270),
(long(9930107427299601010), 273)]
(8921811264899370420, 45), (17019687244989530680, 270),
(9930107427299601010, 273)]
dtype = [('uid', 'u8'), ('score', 'u8')]
data = np.zeros((len(data_scores),), dtype=dtype)
data[:] = data_scores
Expand Down
4 changes: 1 addition & 3 deletions pandas/tests/frame/test_convert_to.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import pytest
import pytz

from pandas.compat import long

from pandas import (
CategoricalDtype, DataFrame, MultiIndex, Series, Timestamp, compat,
date_range)
Expand Down Expand Up @@ -472,7 +470,7 @@ def test_to_dict_box_scalars(self, orient, item_getter):
# make sure that we are boxing properly
df = DataFrame({'a': [1, 2], 'b': [.1, .2]})
result = df.to_dict(orient=orient)
assert isinstance(item_getter(result, 'a', 0), (int, long))
assert isinstance(item_getter(result, 'a', 0), int)
assert isinstance(item_getter(result, 'b', 0), float)

def test_frame_to_dict_tz(self):
Expand Down
23 changes: 9 additions & 14 deletions pandas/tests/frame/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import pytest

from pandas._libs.tslib import iNaT
from pandas.compat import long, lrange, lzip
from pandas.compat import lrange, lzip

from pandas.core.dtypes.common import is_float_dtype, is_integer, is_scalar
from pandas.core.dtypes.dtypes import CategoricalDtype
Expand Down Expand Up @@ -2560,19 +2560,14 @@ def test_boolean_indexing(self):

def test_boolean_indexing_mixed(self):
df = DataFrame({
long(0): {35: np.nan, 40: np.nan, 43: np.nan,
49: np.nan, 50: np.nan},
long(1): {35: np.nan,
40: 0.32632316859446198,
43: np.nan,
49: 0.32632316859446198,
50: 0.39114724480578139},
long(2): {35: np.nan, 40: np.nan, 43: 0.29012581014105987,
49: np.nan, 50: np.nan},
long(3): {35: np.nan, 40: np.nan, 43: np.nan, 49: np.nan,
50: np.nan},
long(4): {35: 0.34215328467153283, 40: np.nan, 43: np.nan,
49: np.nan, 50: np.nan},
0: {35: np.nan, 40: np.nan, 43: np.nan, 49: np.nan, 50: np.nan},
1: {35: np.nan, 40: 0.32632316859446198, 43: np.nan,
49: 0.32632316859446198, 50: 0.39114724480578139},
2: {35: np.nan, 40: np.nan, 43: 0.29012581014105987, 49: np.nan,
50: np.nan},
3: {35: np.nan, 40: np.nan, 43: np.nan, 49: np.nan, 50: np.nan},
4: {35: 0.34215328467153283, 40: np.nan, 43: np.nan, 49: np.nan,
50: np.nan},
'y': {35: 0, 40: 0, 43: 0, 49: 0, 50: 1}})

# mixed int/float ok
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/groupby/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ def test_empty_groups_corner(mframe):

def test_nonsense_func():
df = DataFrame([0])
msg = r"unsupported operand type\(s\) for \+: '(int|long)' and 'str'"
msg = r"unsupported operand type\(s\) for \+: 'int' and 'str'"
with pytest.raises(TypeError, match=msg):
df.groupby(lambda x: x + 'foo')

Expand Down
8 changes: 4 additions & 4 deletions pandas/tests/groupby/test_grouping.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import numpy as np
import pytest

from pandas.compat import long, lrange
from pandas.compat import lrange

import pandas as pd
from pandas import (
Expand Down Expand Up @@ -396,21 +396,21 @@ def test_multiindex_columns_empty_level(self):
lst = [['count', 'values'], ['to filter', '']]
midx = MultiIndex.from_tuples(lst)

df = DataFrame([[long(1), 'A']], columns=midx)
df = DataFrame([[1, 'A']], columns=midx)

grouped = df.groupby('to filter').groups
assert grouped['A'] == [0]

grouped = df.groupby([('to filter', '')]).groups
assert grouped['A'] == [0]

df = DataFrame([[long(1), 'A'], [long(2), 'B']], columns=midx)
df = DataFrame([[1, 'A'], [2, 'B']], columns=midx)

expected = df.groupby('to filter').groups
result = df.groupby([('to filter', '')]).groups
assert result == expected

df = DataFrame([[long(1), 'A'], [long(2), 'A']], columns=midx)
df = DataFrame([[1, 'A'], [2, 'A']], columns=midx)

expected = df.groupby('to filter').groups
result = df.groupby([('to filter', '')]).groups
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/indexes/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
import pytest

from pandas.compat import long, lzip
from pandas.compat import lzip

import pandas as pd
from pandas.core.indexes.api import Index, MultiIndex
Expand Down Expand Up @@ -39,7 +39,7 @@ def one(request):
for dtype in [np.int64, np.uint64, np.float64]]
zeros.extend([np.array(0, dtype=dtype)
for dtype in [np.int64, np.uint64, np.float64]])
zeros.extend([0, 0.0, long(0)])
zeros.extend([0, 0.0])


@pytest.fixture(params=zeros)
Expand Down
Loading