diff --git a/pandas/_testing/__init__.py b/pandas/_testing/__init__.py index fc48317114e23..0a62ee956be61 100644 --- a/pandas/_testing/__init__.py +++ b/pandas/_testing/__init__.py @@ -8,6 +8,7 @@ import os import re import string +from sys import byteorder from typing import ( TYPE_CHECKING, Callable, @@ -168,6 +169,8 @@ np.uint32, ] +ENDIAN = {"little": "<", "big": ">"}[byteorder] + NULL_OBJECTS = [None, np.nan, pd.NaT, float("nan"), pd.NA, Decimal("NaN")] NP_NAT_OBJECTS = [ cls("NaT", unit) diff --git a/pandas/tests/arrays/boolean/test_astype.py b/pandas/tests/arrays/boolean/test_astype.py index 57cec70262526..932e903c0e448 100644 --- a/pandas/tests/arrays/boolean/test_astype.py +++ b/pandas/tests/arrays/boolean/test_astype.py @@ -20,7 +20,7 @@ def test_astype(): tm.assert_numpy_array_equal(result, expected) result = arr.astype("str") - expected = np.array(["True", "False", ""], dtype=""], dtype=f"{tm.ENDIAN}U5") tm.assert_numpy_array_equal(result, expected) # no missing values diff --git a/pandas/tests/arrays/boolean/test_construction.py b/pandas/tests/arrays/boolean/test_construction.py index 64b1786cbd101..d26eea19c06e9 100644 --- a/pandas/tests/arrays/boolean/test_construction.py +++ b/pandas/tests/arrays/boolean/test_construction.py @@ -273,7 +273,7 @@ def test_to_numpy(box): arr = con([True, False, None], dtype="boolean") result = arr.to_numpy(dtype="str") - expected = np.array([True, False, pd.NA], dtype=" can convert to bool, otherwise raises diff --git a/pandas/tests/arrays/floating/test_to_numpy.py b/pandas/tests/arrays/floating/test_to_numpy.py index 26e5687b1b4a0..2ed52439adf53 100644 --- a/pandas/tests/arrays/floating/test_to_numpy.py +++ b/pandas/tests/arrays/floating/test_to_numpy.py @@ -115,7 +115,7 @@ def test_to_numpy_string(box, dtype): arr = con([0.0, 1.0, None], dtype="Float64") result = arr.to_numpy(dtype="str") - expected = np.array([0.0, 1.0, pd.NA], dtype=""], dtype=""], dtype=f"{tm.ENDIAN}U21") tm.assert_numpy_array_equal(a.astype(str), expected) tm.assert_numpy_array_equal(a.astype("str"), expected) diff --git a/pandas/tests/frame/methods/test_to_records.py b/pandas/tests/frame/methods/test_to_records.py index 1a84fb73fd524..6332ffd181eba 100644 --- a/pandas/tests/frame/methods/test_to_records.py +++ b/pandas/tests/frame/methods/test_to_records.py @@ -151,7 +151,12 @@ def test_to_records_with_categorical(self): {}, np.rec.array( [(0, 1, 0.2, "a"), (1, 2, 1.5, "bc")], - dtype=[("index", "