Skip to content

CLN: use IS64 instead of is_platform_32bit #36108 #36109

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
Sep 4, 2020
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
4 changes: 2 additions & 2 deletions pandas/_libs/missing.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ from pandas._libs.tslibs.nattype cimport (
from pandas._libs.tslibs.np_datetime cimport get_datetime64_value, get_timedelta64_value

from pandas._libs.ops_dispatch import maybe_dispatch_ufunc_to_dunder_op
from pandas.compat import is_platform_32bit
from pandas.compat import IS64

cdef:
float64_t INF = <float64_t>np.inf
float64_t NEGINF = -INF

int64_t NPY_NAT = util.get_nat()

bint is_32bit = is_platform_32bit()
bint is_32bit = not IS64


cpdef bint checknull(object val):
Expand Down
24 changes: 1 addition & 23 deletions pandas/compat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* platform checker
"""
import platform
import struct
import sys
import warnings

Expand All @@ -20,14 +19,6 @@
IS64 = sys.maxsize > 2 ** 32


# ----------------------------------------------------------------------------
# functions largely based / taken from the six module

# Much of the code in this module comes from Benjamin Peterson's six library.
# The license for this library can be found in LICENSES/SIX and the code can be
# found at https://bitbucket.org/gutworth/six


Comment on lines -23 to -30
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The LICENSES folder doesn't contain SIX. So I guess this comment is not valid anymore.

def set_function_name(f: F, name: str, cls) -> F:
"""
Bind the name/qualname attributes of the function.
Expand All @@ -38,7 +29,6 @@ def set_function_name(f: F, name: str, cls) -> F:
return f


# https://github.com/pandas-dev/pandas/pull/9123
def is_platform_little_endian() -> bool:
"""
Checking if the running platform is little endian.
Expand Down Expand Up @@ -72,7 +62,7 @@ def is_platform_linux() -> bool:
bool
True if the running platform is linux.
"""
return sys.platform == "linux2"
return sys.platform == "linux"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was changed to "linux" in Python 3.3

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh lol, i don't think this is actually used anyhow (but good to change)



def is_platform_mac() -> bool:
Expand All @@ -87,18 +77,6 @@ def is_platform_mac() -> bool:
return sys.platform == "darwin"


def is_platform_32bit() -> bool:
"""
Checking if the running platform is 32-bit.

Returns
-------
bool
True if the running platform is 32-bit.
"""
return struct.calcsize("P") * 8 < 64


def _import_lzma():
"""
Importing the `lzma` module.
Expand Down
5 changes: 3 additions & 2 deletions pandas/tests/frame/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
import numpy as np
import pytest

from pandas.compat import IS64, is_platform_windows
import pandas.util._test_decorators as td
from pandas.util._test_decorators import async_mark, skip_if_no

import pandas as pd
from pandas import Categorical, DataFrame, Series, compat, date_range, timedelta_range
from pandas import Categorical, DataFrame, Series, date_range, timedelta_range
import pandas._testing as tm


Expand Down Expand Up @@ -254,7 +255,7 @@ def test_itertuples(self, float_frame):
assert list(dfaa.itertuples()) == [(0, 1, 1), (1, 2, 2), (2, 3, 3)]

# repr with int on 32-bit/windows
if not (compat.is_platform_windows() or compat.is_platform_32bit()):
if not (is_platform_windows() or not IS64):
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/indexes/interval/test_interval_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import pytest

from pandas._libs.interval import IntervalTree
from pandas.compat import IS64

from pandas import compat
import pandas._testing as tm


Expand All @@ -14,9 +14,7 @@ def skipif_32bit(param):
Skip parameters in a parametrize on 32bit systems. Specifically used
here to skip leaf_size parameters related to GH 23440.
"""
marks = pytest.mark.skipif(
compat.is_platform_32bit(), reason="GH 23440: int type mismatch on 32bit"
)
marks = pytest.mark.skipif(not IS64, reason="GH 23440: int type mismatch on 32bit")
return pytest.param(param, marks=marks)


Expand Down Expand Up @@ -181,7 +179,7 @@ def test_is_overlapping_trivial(self, closed, left, right):
tree = IntervalTree(left, right, closed=closed)
assert tree.is_overlapping is False

@pytest.mark.skipif(compat.is_platform_32bit(), reason="GH 23440")
@pytest.mark.skipif(not IS64, reason="GH 23440")
def test_construction_overflow(self):
# GH 25485
left, right = np.arange(101, dtype="int64"), [np.iinfo(np.int64).max] * 101
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/indexing/test_coercion.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import numpy as np
import pytest

import pandas.compat as compat
from pandas.compat import IS64, is_platform_windows

import pandas as pd
import pandas._testing as tm
Expand Down Expand Up @@ -1041,7 +1041,7 @@ def test_replace_series(self, how, to_key, from_key):
from_key == "complex128" and to_key in ("int64", "float64")
):

if compat.is_platform_32bit() or compat.is_platform_windows():
if not IS64 or is_platform_windows():
pytest.skip(f"32-bit platform buggy: {from_key} -> {to_key}")

# Expected: do not downcast by replacement
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/io/formats/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import pytest
import pytz

from pandas.compat import is_platform_32bit, is_platform_windows
from pandas.compat import IS64, is_platform_windows
import pandas.util._test_decorators as td

import pandas as pd
Expand All @@ -41,7 +41,7 @@
import pandas.io.formats.format as fmt
import pandas.io.formats.printing as printing

use_32bit_repr = is_platform_windows() or is_platform_32bit()
use_32bit_repr = is_platform_windows() or not IS64


@pytest.fixture(params=["string", "pathlike", "buffer"])
Expand Down
8 changes: 3 additions & 5 deletions pandas/tests/io/json/test_pandas.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 is_platform_32bit, is_platform_windows
from pandas.compat import IS64, is_platform_windows
import pandas.util._test_decorators as td

import pandas as pd
Expand Down Expand Up @@ -154,7 +154,7 @@ def test_roundtrip_intframe(self, orient, convert_axes, numpy, dtype, int_frame)
expected = int_frame
if (
numpy
and (is_platform_32bit() or is_platform_windows())
and (not IS64 or is_platform_windows())
and not dtype
and orient != "split"
):
Expand Down Expand Up @@ -361,9 +361,7 @@ def test_frame_infinity(self, orient, inf, dtype):
result = read_json(df.to_json(), dtype=dtype)
assert np.isnan(result.iloc[0, 2])

@pytest.mark.skipif(
is_platform_32bit(), reason="not compliant on 32-bit, xref #15865"
)
@pytest.mark.skipif(not IS64, reason="not compliant on 32-bit, xref #15865")
@pytest.mark.parametrize(
"value,precision,expected_val",
[
Expand Down
12 changes: 5 additions & 7 deletions pandas/tests/io/json/test_ujson.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import pandas._libs.json as ujson
from pandas._libs.tslib import Timestamp
import pandas.compat as compat
from pandas.compat import IS64, is_platform_windows

from pandas import DataFrame, DatetimeIndex, Index, NaT, Series, Timedelta, date_range
import pandas._testing as tm
Expand Down Expand Up @@ -53,7 +53,7 @@ def get_int32_compat_dtype(numpy, orient):
# See GH#32527
dtype = np.int64
if not ((numpy is None or orient == "index") or (numpy is True and orient is None)):
if compat.is_platform_windows():
if is_platform_windows():
dtype = np.int32
else:
dtype = np.intp
Expand All @@ -62,9 +62,7 @@ def get_int32_compat_dtype(numpy, orient):


class TestUltraJSONTests:
@pytest.mark.skipif(
compat.is_platform_32bit(), reason="not compliant on 32-bit, xref #15865"
)
@pytest.mark.skipif(not IS64, reason="not compliant on 32-bit, xref #15865")
def test_encode_decimal(self):
sut = decimal.Decimal("1337.1337")
encoded = ujson.encode(sut, double_precision=15)
Expand Down Expand Up @@ -561,7 +559,7 @@ def test_encode_long_conversion(self):
assert long_input == ujson.decode(output)

@pytest.mark.parametrize("bigNum", [sys.maxsize + 1, -(sys.maxsize + 2)])
@pytest.mark.xfail(not compat.IS64, reason="GH-35288")
@pytest.mark.xfail(not IS64, reason="GH-35288")
def test_dumps_ints_larger_than_maxsize(self, bigNum):
# GH34395
bigNum = sys.maxsize + 1
Expand Down Expand Up @@ -703,7 +701,7 @@ def test_int_array(self, any_int_dtype):
tm.assert_numpy_array_equal(arr_input, arr_output)

def test_int_max(self, any_int_dtype):
if any_int_dtype in ("int64", "uint64") and compat.is_platform_32bit():
if any_int_dtype in ("int64", "uint64") and not IS64:
pytest.skip("Cannot test 64-bit integer on 32-bit platform")

klass = np.dtype(any_int_dtype).type
Expand Down
6 changes: 3 additions & 3 deletions pandas/tests/test_algos.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from pandas._libs import algos as libalgos, hashtable as ht
from pandas._libs.groupby import group_var_float32, group_var_float64
from pandas.compat import IS64
from pandas.compat.numpy import np_array_datetime64_compat
import pandas.util._test_decorators as td

Expand All @@ -29,7 +30,6 @@
IntervalIndex,
Series,
Timestamp,
compat,
)
import pandas._testing as tm
import pandas.core.algorithms as algos
Expand Down Expand Up @@ -1137,7 +1137,7 @@ def test_dropna(self):
)

# 32-bit linux has a different ordering
if not compat.is_platform_32bit():
if IS64:
result = Series([10.3, 5.0, 5.0, None]).value_counts(dropna=False)
expected = Series([2, 1, 1], index=[5.0, 10.3, np.nan])
tm.assert_series_equal(result, expected)
Expand Down Expand Up @@ -1170,7 +1170,7 @@ def test_value_counts_uint64(self):
result = algos.value_counts(arr)

# 32-bit linux has a different ordering
if not compat.is_platform_32bit():
if IS64:
tm.assert_series_equal(result, expected)


Expand Down
4 changes: 2 additions & 2 deletions pandas/util/_test_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_foo():
import numpy as np
import pytest

from pandas.compat import is_platform_32bit, is_platform_windows
from pandas.compat import IS64, is_platform_windows
from pandas.compat._optional import import_optional_dependency
from pandas.compat.numpy import _np_version

Expand Down Expand Up @@ -180,7 +180,7 @@ def skip_if_no(package: str, min_version: Optional[str] = None):
_skip_if_no_mpl(), reason="Missing matplotlib dependency"
)
skip_if_mpl = pytest.mark.skipif(not _skip_if_no_mpl(), reason="matplotlib is present")
skip_if_32bit = pytest.mark.skipif(is_platform_32bit(), reason="skipping for 32 bit")
skip_if_32bit = pytest.mark.skipif(not IS64, reason="skipping for 32 bit")
skip_if_windows = pytest.mark.skipif(is_platform_windows(), reason="Running on Windows")
skip_if_windows_python_3 = pytest.mark.skipif(
is_platform_windows(), reason="not used on win32"
Expand Down