From 18422e3c73642042322eea14c3e8a6a67051fe34 Mon Sep 17 00:00:00 2001 From: Jeremy Schendel Date: Sun, 24 Mar 2019 13:49:33 -0600 Subject: [PATCH] CLN: Remove long and integer_types from pandas.compat --- pandas/compat/__init__.py | 5 ---- pandas/core/internals/blocks.py | 10 +++---- pandas/core/sorting.py | 10 +++---- pandas/io/json/json.py | 10 +++---- pandas/io/stata.py | 8 +++--- pandas/tests/arithmetic/conftest.py | 4 +-- pandas/tests/arithmetic/test_period.py | 2 +- .../tests/arrays/categorical/test_dtypes.py | 7 ++--- pandas/tests/arrays/test_datetimelike.py | 6 ++--- pandas/tests/arrays/test_integer.py | 1 - pandas/tests/frame/test_api.py | 6 ++--- pandas/tests/frame/test_constructors.py | 8 +++--- pandas/tests/frame/test_convert_to.py | 4 +-- pandas/tests/frame/test_indexing.py | 23 +++++++--------- pandas/tests/groupby/test_groupby.py | 2 +- pandas/tests/groupby/test_grouping.py | 8 +++--- pandas/tests/indexes/conftest.py | 4 +-- .../indexes/datetimes/test_date_range.py | 6 ++--- pandas/tests/indexes/multi/test_compat.py | 4 +-- pandas/tests/reshape/test_concat.py | 8 +++--- .../tests/scalar/timedelta/test_timedelta.py | 5 ++-- .../tests/scalar/timestamp/test_arithmetic.py | 4 +-- .../scalar/timestamp/test_comparisons.py | 6 +---- .../tests/scalar/timestamp/test_timestamp.py | 22 +++++++--------- pandas/tests/series/test_constructors.py | 3 +-- pandas/tests/series/test_dtypes.py | 2 +- pandas/tests/test_base.py | 26 +++++++++---------- pandas/tests/test_take.py | 4 +-- pandas/tests/tools/test_numeric.py | 5 +--- 29 files changed, 86 insertions(+), 127 deletions(-) diff --git a/pandas/compat/__init__.py b/pandas/compat/__init__.py index fcdbfc0639157..17a75303a617c 100644 --- a/pandas/compat/__init__.py +++ b/pandas/compat/__init__.py @@ -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: @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index 979c9fb8b825b..c1ba146ba0c9a 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -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): @@ -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) diff --git a/pandas/core/sorting.py b/pandas/core/sorting.py index 0b5b017bec9ac..e1cf5b76ba05b 100644 --- a/pandas/core/sorting.py +++ b/pandas/core/sorting.py @@ -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 ( @@ -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) @@ -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 diff --git a/pandas/io/json/json.py b/pandas/io/json/json.py index 3eca54cc42ef4..8c13d93a82bcf 100644 --- a/pandas/io/json/json.py +++ b/pandas/io/json/json.py @@ -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 @@ -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, diff --git a/pandas/io/stata.py b/pandas/io/stata.py index 9b65ceca50531..ec768d68a2ffd 100644 --- a/pandas/io/stata.py +++ b/pandas/io/stata.py @@ -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(' " - r"(int|long|float|str)\(\)|" - r"Expected tuple, got (int|long|float|str)|" - r"Cannot compare type 'Timestamp' with type '(int|long)'|" + r"(int|float|str)\(\)|" + r"Expected tuple, got (int|float|str)|" + r"Cannot compare type 'Timestamp' with type 'int'|" r"'>' not supported between instances of 'int' and 'str'") with pytest.raises(TypeError, match=msg): df.append(ser) diff --git a/pandas/tests/scalar/timedelta/test_timedelta.py b/pandas/tests/scalar/timedelta/test_timedelta.py index 7a324df163a32..df68d56b8276c 100644 --- a/pandas/tests/scalar/timedelta/test_timedelta.py +++ b/pandas/tests/scalar/timedelta/test_timedelta.py @@ -6,7 +6,6 @@ import pytest from pandas._libs.tslibs import NaT, iNaT -import pandas.compat as compat import pandas as pd from pandas import ( @@ -240,8 +239,8 @@ def test_freq_conversion(self): def test_fields(self): def check(value): - # that we are int/long like - assert isinstance(value, (int, compat.long)) + # that we are int + assert isinstance(value, int) # compat to datetime.timedelta rng = to_timedelta('1 days, 10:11:12') diff --git a/pandas/tests/scalar/timestamp/test_arithmetic.py b/pandas/tests/scalar/timestamp/test_arithmetic.py index 331d66589802d..5aff646820862 100644 --- a/pandas/tests/scalar/timestamp/test_arithmetic.py +++ b/pandas/tests/scalar/timestamp/test_arithmetic.py @@ -4,8 +4,6 @@ import numpy as np import pytest -from pandas.compat import long - from pandas import Timedelta, Timestamp import pandas.util.testing as tm @@ -63,7 +61,7 @@ def test_overflow_offset_raises(self): stamp - offset_overflow def test_delta_preserve_nanos(self): - val = Timestamp(long(1337299200000000123)) + val = Timestamp(1337299200000000123) result = val + timedelta(1) assert result.nanosecond == val.nanosecond diff --git a/pandas/tests/scalar/timestamp/test_comparisons.py b/pandas/tests/scalar/timestamp/test_comparisons.py index 9a76896b23deb..b0b723e66c649 100644 --- a/pandas/tests/scalar/timestamp/test_comparisons.py +++ b/pandas/tests/scalar/timestamp/test_comparisons.py @@ -5,8 +5,6 @@ import numpy as np import pytest -from pandas.compat import long - from pandas import Timestamp @@ -38,7 +36,7 @@ def test_comparison_object_array(self): def test_comparison(self): # 5-18-2012 00:00:00.000 - stamp = long(1337299200000000000) + stamp = 1337299200000000000 val = Timestamp(stamp) @@ -72,7 +70,6 @@ def test_compare_invalid(self): assert not val == 'foo' assert not val == 10.0 assert not val == 1 - assert not val == long(1) assert not val == [] assert not val == {'foo': 1} assert not val == np.float64(1) @@ -81,7 +78,6 @@ def test_compare_invalid(self): assert val != 'foo' assert val != 10.0 assert val != 1 - assert val != long(1) assert val != [] assert val != {'foo': 1} assert val != np.float64(1) diff --git a/pandas/tests/scalar/timestamp/test_timestamp.py b/pandas/tests/scalar/timestamp/test_timestamp.py index 0466deb4a29a0..65575e0419746 100644 --- a/pandas/tests/scalar/timestamp/test_timestamp.py +++ b/pandas/tests/scalar/timestamp/test_timestamp.py @@ -14,7 +14,6 @@ from pandas._libs.tslibs import conversion from pandas._libs.tslibs.timezones import dateutil_gettz as gettz, get_timezone -from pandas.compat import long from pandas.compat.numpy import np_datetime64_compat from pandas.errors import OutOfBoundsDatetime import pandas.util._test_decorators as td @@ -48,8 +47,8 @@ def test_properties_business(self): def test_fields(self): def check(value, equal): - # that we are int/long like - assert isinstance(value, (int, long)) + # that we are int like + assert isinstance(value, int) assert value == equal # GH 10050 @@ -699,18 +698,17 @@ def test_basics_nanos(self): @pytest.mark.parametrize('value, check_kwargs', [ [946688461000000000, {}], - [946688461000000000 / long(1000), dict(unit='us')], - [946688461000000000 / long(1000000), dict(unit='ms')], - [946688461000000000 / long(1000000000), dict(unit='s')], + [946688461000000000 / 1000, dict(unit='us')], + [946688461000000000 / 1000000, dict(unit='ms')], + [946688461000000000 / 1000000000, dict(unit='s')], [10957, dict(unit='D', h=0)], - [(946688461000000000 + 500000) / long(1000000000), + [(946688461000000000 + 500000) / 1000000000, dict(unit='s', us=499, ns=964)], - [(946688461000000000 + 500000000) / long(1000000000), + [(946688461000000000 + 500000000) / 1000000000, dict(unit='s', us=500000)], - [(946688461000000000 + 500000) / long(1000000), - dict(unit='ms', us=500)], - [(946688461000000000 + 500000) / long(1000), dict(unit='us', us=500)], - [(946688461000000000 + 500000000) / long(1000000), + [(946688461000000000 + 500000) / 1000000, dict(unit='ms', us=500)], + [(946688461000000000 + 500000) / 1000, dict(unit='us', us=500)], + [(946688461000000000 + 500000000) / 1000000, dict(unit='ms', us=500000)], [946688461000000000 / 1000.0 + 5, dict(unit='us', us=5)], [946688461000000000 / 1000.0 + 5000, dict(unit='us', us=5000)], diff --git a/pandas/tests/series/test_constructors.py b/pandas/tests/series/test_constructors.py index 54d9359e5aa78..029924597ccd2 100644 --- a/pandas/tests/series/test_constructors.py +++ b/pandas/tests/series/test_constructors.py @@ -11,7 +11,7 @@ from pandas._libs import lib from pandas._libs.tslib import iNaT -from pandas.compat import PY36, long, lrange +from pandas.compat import PY36, lrange from pandas.core.dtypes.common import ( is_categorical_dtype, is_datetime64tz_dtype) @@ -45,7 +45,6 @@ def test_scalar_conversion(self): # Coercion assert float(Series([1.])) == 1.0 assert int(Series([1.])) == 1 - assert long(Series([1.])) == 1 def test_constructor(self, datetime_series): empty_series = Series() diff --git a/pandas/tests/series/test_dtypes.py b/pandas/tests/series/test_dtypes.py index f27ae68080794..c90437a730631 100644 --- a/pandas/tests/series/test_dtypes.py +++ b/pandas/tests/series/test_dtypes.py @@ -74,7 +74,7 @@ def test_astype_cast_nan_inf_int(self, dtype, value): @pytest.mark.parametrize("dtype", [int, np.int8, np.int64]) def test_astype_cast_object_int_fail(self, dtype): arr = Series(["car", "house", "tree", "1"]) - msg = r"invalid literal for (int|long)\(\) with base 10: 'car'" + msg = r"invalid literal for int\(\) with base 10: 'car'" with pytest.raises(ValueError, match=msg): arr.astype(dtype) diff --git a/pandas/tests/test_base.py b/pandas/tests/test_base.py index feacbd11a1ef6..600bec198ac40 100644 --- a/pandas/tests/test_base.py +++ b/pandas/tests/test_base.py @@ -9,7 +9,7 @@ import pytest from pandas._libs.tslib import iNaT -from pandas.compat import PYPY, StringIO, long +from pandas.compat import PYPY, StringIO from pandas.compat.numpy import np_array_datetime64_compat from pandas.core.dtypes.common import ( @@ -1006,14 +1006,14 @@ class TestToIterable(object): # test that we convert an iterable to python types dtypes = [ - ('int8', (int, long)), - ('int16', (int, long)), - ('int32', (int, long)), - ('int64', (int, long)), - ('uint8', (int, long)), - ('uint16', (int, long)), - ('uint32', (int, long)), - ('uint64', (int, long)), + ('int8', int), + ('int16', int), + ('int32', int), + ('int64', int), + ('uint8', int), + ('uint16', int), + ('uint32', int), + ('uint64', int), ('float16', float), ('float32', float), ('float64', float), @@ -1046,9 +1046,9 @@ def test_iterable(self, typ, method, dtype, rdtype): 'dtype, rdtype, obj', [ ('object', object, 'a'), - ('object', (int, long), 1), + ('object', int, 1), ('category', object, 'a'), - ('category', (int, long), 1)]) + ('category', int, 1)]) @pytest.mark.parametrize( 'method', [ @@ -1083,8 +1083,8 @@ def test_iterable_items(self, dtype, rdtype): @pytest.mark.parametrize( 'dtype, rdtype', dtypes + [ - ('object', (int, long)), - ('category', (int, long))]) + ('object', int), + ('category', int)]) @pytest.mark.parametrize('typ', [Series, Index]) @pytest.mark.filterwarnings("ignore:\\n Passing:FutureWarning") # TODO(GH-24559): Remove the filterwarnings diff --git a/pandas/tests/test_take.py b/pandas/tests/test_take.py index c9e4ed90b1dea..b2e695bdea17d 100644 --- a/pandas/tests/test_take.py +++ b/pandas/tests/test_take.py @@ -6,7 +6,6 @@ import pytest from pandas._libs.tslib import iNaT -from pandas.compat import long import pandas.core.algorithms as algos import pandas.util.testing as tm @@ -353,8 +352,7 @@ def test_2d_float32(self): def test_2d_datetime64(self): # 2005/01/01 - 2006/01/01 - arr = np.random.randint( - long(11045376), long(11360736), (5, 3)) * 100000000000 + arr = np.random.randint(11045376, 11360736, (5, 3)) * 100000000000 arr = arr.view(dtype='datetime64[ns]') indexer = [0, 2, -1, 1, -1] diff --git a/pandas/tests/tools/test_numeric.py b/pandas/tests/tools/test_numeric.py index 97e1dc2f6aefc..ee2c2c0c3cdfa 100644 --- a/pandas/tests/tools/test_numeric.py +++ b/pandas/tests/tools/test_numeric.py @@ -4,8 +4,6 @@ from numpy import iinfo import pytest -import pandas.compat as compat - import pandas as pd from pandas import DataFrame, Index, Series, to_numeric from pandas.util import testing as tm @@ -280,8 +278,7 @@ def test_really_large_in_arr(large_val, signed, transform, expected.append(extra_elt) exp_dtype = object else: - exp_dtype = float if isinstance(exp_val, ( - int, compat.long, float)) else object + exp_dtype = float if isinstance(exp_val, (int, float)) else object tm.assert_almost_equal(result, np.array(expected, dtype=exp_dtype))