From d8a7111477743436c788fab18e5b5d7e7b80c7ff Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Sat, 7 Mar 2020 11:50:56 -0800 Subject: [PATCH 1/9] TST: make tests stricter --- pandas/tests/arithmetic/test_numeric.py | 18 +++++++++--------- .../dtypes/cast/test_construct_from_scalar.py | 4 +--- pandas/tests/frame/test_constructors.py | 5 +---- pandas/tests/generic/test_series.py | 4 +--- pandas/tests/io/excel/test_writers.py | 2 +- pandas/tests/io/json/test_pandas.py | 1 - pandas/tests/io/json/test_ujson.py | 4 ++-- pandas/tests/io/pytables/test_store.py | 14 ++------------ pandas/tests/io/test_clipboard.py | 2 +- pandas/tests/reshape/merge/test_join.py | 2 +- .../tests/reshape/test_union_categoricals.py | 2 +- pandas/tests/series/methods/test_argsort.py | 4 ++-- pandas/tests/series/methods/test_replace.py | 2 +- pandas/tests/series/test_constructors.py | 2 +- pandas/tests/series/test_duplicates.py | 4 ++-- 15 files changed, 26 insertions(+), 44 deletions(-) diff --git a/pandas/tests/arithmetic/test_numeric.py b/pandas/tests/arithmetic/test_numeric.py index d4baf2f374cdf..202e30287881f 100644 --- a/pandas/tests/arithmetic/test_numeric.py +++ b/pandas/tests/arithmetic/test_numeric.py @@ -913,13 +913,13 @@ def test_frame_operators(self, float_frame): # TODO: taken from tests.series.test_operators; needs cleanup def test_series_operators(self): - def _check_op(series, other, op, pos_only=False, check_dtype=True): + def _check_op(series, other, op, pos_only=False): left = np.abs(series) if pos_only else series right = np.abs(other) if pos_only else other cython_or_numpy = op(left, right) python = left.combine(right, op) - tm.assert_series_equal(cython_or_numpy, python, check_dtype=check_dtype) + tm.assert_series_equal(cython_or_numpy, python) def check(series, other): simple_ops = ["add", "sub", "mul", "truediv", "floordiv", "mod"] @@ -942,15 +942,15 @@ def check(series, other): check(tser, tser[::2]) check(tser, 5) - def check_comparators(series, other, check_dtype=True): - _check_op(series, other, operator.gt, check_dtype=check_dtype) - _check_op(series, other, operator.ge, check_dtype=check_dtype) - _check_op(series, other, operator.eq, check_dtype=check_dtype) - _check_op(series, other, operator.lt, check_dtype=check_dtype) - _check_op(series, other, operator.le, check_dtype=check_dtype) + def check_comparators(series, other): + _check_op(series, other, operator.gt) + _check_op(series, other, operator.ge) + _check_op(series, other, operator.eq) + _check_op(series, other, operator.lt) + _check_op(series, other, operator.le) check_comparators(tser, 5) - check_comparators(tser, tser + 1, check_dtype=False) + check_comparators(tser, tser + 1) # TODO: taken from tests.series.test_operators; needs cleanup def test_divmod(self): diff --git a/pandas/tests/dtypes/cast/test_construct_from_scalar.py b/pandas/tests/dtypes/cast/test_construct_from_scalar.py index cc823a3d6e02c..ed272cef3e7ba 100644 --- a/pandas/tests/dtypes/cast/test_construct_from_scalar.py +++ b/pandas/tests/dtypes/cast/test_construct_from_scalar.py @@ -15,6 +15,4 @@ def test_cast_1d_array_like_from_scalar_categorical(): expected = Categorical(["a", "a"], categories=cats) result = construct_1d_arraylike_from_scalar("a", len(expected), cat_type) - tm.assert_categorical_equal( - result, expected, check_category_order=True, check_dtype=True - ) + tm.assert_categorical_equal(result, expected) diff --git a/pandas/tests/frame/test_constructors.py b/pandas/tests/frame/test_constructors.py index 071d2409f1be2..172800e74d181 100644 --- a/pandas/tests/frame/test_constructors.py +++ b/pandas/tests/frame/test_constructors.py @@ -916,10 +916,7 @@ def test_constructor_mrecarray(self): # from GH3479 assert_fr_equal = functools.partial( - tm.assert_frame_equal, - check_index_type=True, - check_column_type=True, - check_frame_type=True, + tm.assert_frame_equal, check_index_type=True, check_column_type=True, ) arrays = [ ("float", np.array([1.5, 2.0])), diff --git a/pandas/tests/generic/test_series.py b/pandas/tests/generic/test_series.py index f119eb422a276..388bb8e3f636d 100644 --- a/pandas/tests/generic/test_series.py +++ b/pandas/tests/generic/test_series.py @@ -237,9 +237,7 @@ def test_to_xarray_index_types(self, index): assert isinstance(result, DataArray) # idempotency - tm.assert_series_equal( - result.to_series(), s, check_index_type=False, check_categorical=True - ) + tm.assert_series_equal(result.to_series(), s, check_index_type=False) @td.skip_if_no("xarray", min_version="0.7.0") def test_to_xarray(self): diff --git a/pandas/tests/io/excel/test_writers.py b/pandas/tests/io/excel/test_writers.py index 506d223dbedb4..44d229ea5b9ee 100644 --- a/pandas/tests/io/excel/test_writers.py +++ b/pandas/tests/io/excel/test_writers.py @@ -452,7 +452,7 @@ def test_float_types(self, np_type, path): reader = ExcelFile(path) recons = pd.read_excel(reader, "test1", index_col=0).astype(np_type) - tm.assert_frame_equal(df, recons, check_dtype=False) + tm.assert_frame_equal(df, recons) @pytest.mark.parametrize("np_type", [np.bool8, np.bool_]) def test_bool_types(self, np_type, path): diff --git a/pandas/tests/io/json/test_pandas.py b/pandas/tests/io/json/test_pandas.py index f2d35bfb3b5ae..276dfd666c5d0 100644 --- a/pandas/tests/io/json/test_pandas.py +++ b/pandas/tests/io/json/test_pandas.py @@ -572,7 +572,6 @@ def test_blocks_compat_GH9037(self): df_roundtrip, check_index_type=True, check_column_type=True, - check_frame_type=True, by_blocks=True, check_exact=True, ) diff --git a/pandas/tests/io/json/test_ujson.py b/pandas/tests/io/json/test_ujson.py index e966db7a1cc71..a25a08249c841 100644 --- a/pandas/tests/io/json/test_ujson.py +++ b/pandas/tests/io/json/test_ujson.py @@ -857,7 +857,7 @@ def test_dataframe(self, orient, numpy): elif orient == "index": df = df.transpose() - tm.assert_frame_equal(output, df, check_dtype=False) + tm.assert_frame_equal(output, df) def test_dataframe_nested(self, orient): df = DataFrame( @@ -920,7 +920,7 @@ def test_series(self, orient, numpy): s.name = None s.index = [0, 1, 2, 3, 4, 5] - tm.assert_series_equal(output, s, check_dtype=False) + tm.assert_series_equal(output, s) def test_series_nested(self, orient): s = Series( diff --git a/pandas/tests/io/pytables/test_store.py b/pandas/tests/io/pytables/test_store.py index fd585a73f6ce6..82c8c4e13b763 100644 --- a/pandas/tests/io/pytables/test_store.py +++ b/pandas/tests/io/pytables/test_store.py @@ -13,8 +13,6 @@ from pandas.compat import is_platform_little_endian, is_platform_windows import pandas.util._test_decorators as td -from pandas.core.dtypes.common import is_categorical_dtype - import pandas as pd from pandas import ( Categorical, @@ -1057,13 +1055,7 @@ def test_latin_encoding(self, setup_path, dtype, val): s_nan = ser.replace(nan_rep, np.nan) - if is_categorical_dtype(s_nan): - assert is_categorical_dtype(retr) - tm.assert_series_equal( - s_nan, retr, check_dtype=False, check_categorical=False - ) - else: - tm.assert_series_equal(s_nan, retr) + tm.assert_series_equal(s_nan, retr) # FIXME: don't leave commented-out # fails: @@ -2311,9 +2303,7 @@ def test_index_types(self, setup_path): with catch_warnings(record=True): values = np.random.randn(2) - func = lambda l, r: tm.assert_series_equal( - l, r, check_dtype=True, check_index_type=True, check_series_type=True - ) + func = lambda l, r: tm.assert_series_equal(l, r, check_index_type=True) with catch_warnings(record=True): ser = Series(values, [0, "y"]) diff --git a/pandas/tests/io/test_clipboard.py b/pandas/tests/io/test_clipboard.py index 3458cfb6ad254..3b0de6c2e790e 100644 --- a/pandas/tests/io/test_clipboard.py +++ b/pandas/tests/io/test_clipboard.py @@ -146,7 +146,7 @@ class TestClipboard: def check_round_trip_frame(self, data, excel=None, sep=None, encoding=None): data.to_clipboard(excel=excel, sep=sep, encoding=encoding) result = read_clipboard(sep=sep or "\t", index_col=0, encoding=encoding) - tm.assert_frame_equal(data, result, check_dtype=False) + tm.assert_frame_equal(data, result) # Test that default arguments copy as tab delimited def test_round_trip_frame(self, df): diff --git a/pandas/tests/reshape/merge/test_join.py b/pandas/tests/reshape/merge/test_join.py index 725157b7c8523..dc1efa46403be 100644 --- a/pandas/tests/reshape/merge/test_join.py +++ b/pandas/tests/reshape/merge/test_join.py @@ -298,7 +298,7 @@ def test_join_on_inner(self): expected = df.join(df2, on="key") expected = expected[expected["value"].notna()] - tm.assert_series_equal(joined["key"], expected["key"], check_dtype=False) + tm.assert_series_equal(joined["key"], expected["key"]) tm.assert_series_equal(joined["value"], expected["value"], check_dtype=False) tm.assert_index_equal(joined.index, expected.index) diff --git a/pandas/tests/reshape/test_union_categoricals.py b/pandas/tests/reshape/test_union_categoricals.py index a503173bd74b1..8918d19e4ba7b 100644 --- a/pandas/tests/reshape/test_union_categoricals.py +++ b/pandas/tests/reshape/test_union_categoricals.py @@ -41,7 +41,7 @@ def test_union_categorical(self): for box in [Categorical, CategoricalIndex, Series]: result = union_categoricals([box(Categorical(a)), box(Categorical(b))]) expected = Categorical(combined) - tm.assert_categorical_equal(result, expected, check_category_order=True) + tm.assert_categorical_equal(result, expected) # new categories ordered by appearance s = Categorical(["x", "y", "z"]) diff --git a/pandas/tests/series/methods/test_argsort.py b/pandas/tests/series/methods/test_argsort.py index c7fe6ed19a2eb..e0f9027a86f58 100644 --- a/pandas/tests/series/methods/test_argsort.py +++ b/pandas/tests/series/methods/test_argsort.py @@ -49,8 +49,8 @@ def test_argsort_stable(self): mexpected = np.argsort(s.values, kind="mergesort") qexpected = np.argsort(s.values, kind="quicksort") - tm.assert_series_equal(mindexer, Series(mexpected), check_dtype=False) - tm.assert_series_equal(qindexer, Series(qexpected), check_dtype=False) + tm.assert_series_equal(mindexer, Series(mexpected)) + tm.assert_series_equal(qindexer, Series(qexpected)) msg = ( r"ndarray Expected type , " r"found instead" diff --git a/pandas/tests/series/methods/test_replace.py b/pandas/tests/series/methods/test_replace.py index 26eaf53616282..904a455870ab1 100644 --- a/pandas/tests/series/methods/test_replace.py +++ b/pandas/tests/series/methods/test_replace.py @@ -294,7 +294,7 @@ def test_replace_categorical(self, categorical, numeric): s = pd.Series(categorical) result = s.replace({"A": 1, "B": 2}) expected = pd.Series(numeric) - tm.assert_series_equal(expected, result, check_dtype=False) + tm.assert_series_equal(expected, result) def test_replace_categorical_single(self): # GH 26988 diff --git a/pandas/tests/series/test_constructors.py b/pandas/tests/series/test_constructors.py index 1a794f8656abe..46ac430a13394 100644 --- a/pandas/tests/series/test_constructors.py +++ b/pandas/tests/series/test_constructors.py @@ -393,7 +393,7 @@ def test_constructor_categorical_dtype(self): expected = Series( ["a", "a"], index=[0, 1], dtype=CategoricalDtype(["a", "b"], ordered=True) ) - tm.assert_series_equal(result, expected, check_categorical=True) + tm.assert_series_equal(result, expected) def test_constructor_categorical_string(self): # GH 26336: the string 'category' maintains existing CategoricalDtype diff --git a/pandas/tests/series/test_duplicates.py b/pandas/tests/series/test_duplicates.py index 3513db6177951..89181a08819b1 100644 --- a/pandas/tests/series/test_duplicates.py +++ b/pandas/tests/series/test_duplicates.py @@ -47,9 +47,9 @@ def test_unique(): # GH 18051 s = Series(Categorical([])) - tm.assert_categorical_equal(s.unique(), Categorical([]), check_dtype=False) + tm.assert_categorical_equal(s.unique(), Categorical([])) s = Series(Categorical([np.nan])) - tm.assert_categorical_equal(s.unique(), Categorical([np.nan]), check_dtype=False) + tm.assert_categorical_equal(s.unique(), Categorical([np.nan])) def test_unique_data_ownership(): From 6a2d40b1dfe304f5f1c067bb721aa8423a419f06 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Mon, 9 Mar 2020 16:12:45 -0700 Subject: [PATCH 2/9] 32bit compat --- pandas/tests/io/json/test_ujson.py | 10 ++++++++-- pandas/tests/io/test_clipboard.py | 6 +++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/pandas/tests/io/json/test_ujson.py b/pandas/tests/io/json/test_ujson.py index a25a08249c841..48e288ab72519 100644 --- a/pandas/tests/io/json/test_ujson.py +++ b/pandas/tests/io/json/test_ujson.py @@ -834,7 +834,10 @@ def test_dataframe(self, orient, numpy): pytest.skip("Not idiomatic pandas") df = DataFrame( - [[1, 2, 3], [4, 5, 6]], index=["a", "b"], columns=["x", "y", "z"] + [[1, 2, 3], [4, 5, 6]], + index=["a", "b"], + columns=["x", "y", "z"], + dtype=np.intp, ) encode_kwargs = {} if orient is None else dict(orient=orient) decode_kwargs = {} if numpy is None else dict(numpy=numpy) @@ -898,7 +901,10 @@ def test_dataframe_numpy_labelled(self, orient): def test_series(self, orient, numpy): s = Series( - [10, 20, 30, 40, 50, 60], name="series", index=[6, 7, 8, 9, 10, 15] + [10, 20, 30, 40, 50, 60], + name="series", + index=[6, 7, 8, 9, 10, 15], + dtype=np.intp, ).sort_values() encode_kwargs = {} if orient is None else dict(orient=orient) diff --git a/pandas/tests/io/test_clipboard.py b/pandas/tests/io/test_clipboard.py index 3b0de6c2e790e..b627e0e1cad54 100644 --- a/pandas/tests/io/test_clipboard.py +++ b/pandas/tests/io/test_clipboard.py @@ -75,7 +75,11 @@ def df(request): ) elif data_type == "mixed": return DataFrame( - {"a": np.arange(1.0, 6.0) + 0.01, "b": np.arange(1, 6), "c": list("abcde")} + { + "a": np.arange(1.0, 6.0) + 0.01, + "b": np.arange(1, 6).astype(np.int64), + "c": list("abcde"), + } ) elif data_type == "float": return tm.makeCustomDataframe( From 53bb6c58afee905cedcdcf7946e6d143e50a4f89 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Mon, 9 Mar 2020 18:17:58 -0700 Subject: [PATCH 3/9] 32bit compat --- pandas/tests/io/json/test_ujson.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/io/json/test_ujson.py b/pandas/tests/io/json/test_ujson.py index 48e288ab72519..40132f58c7f7a 100644 --- a/pandas/tests/io/json/test_ujson.py +++ b/pandas/tests/io/json/test_ujson.py @@ -837,7 +837,7 @@ def test_dataframe(self, orient, numpy): [[1, 2, 3], [4, 5, 6]], index=["a", "b"], columns=["x", "y", "z"], - dtype=np.intp, + dtype=np.int64, ) encode_kwargs = {} if orient is None else dict(orient=orient) decode_kwargs = {} if numpy is None else dict(numpy=numpy) @@ -904,7 +904,7 @@ def test_series(self, orient, numpy): [10, 20, 30, 40, 50, 60], name="series", index=[6, 7, 8, 9, 10, 15], - dtype=np.intp, + dtype=np.int64, ).sort_values() encode_kwargs = {} if orient is None else dict(orient=orient) From 03910670633177e4182c35cd57553193f0d21c4c Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Mon, 9 Mar 2020 18:22:13 -0700 Subject: [PATCH 4/9] 32bit compat more --- pandas/tests/io/json/test_ujson.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pandas/tests/io/json/test_ujson.py b/pandas/tests/io/json/test_ujson.py index 40132f58c7f7a..61532dabad832 100644 --- a/pandas/tests/io/json/test_ujson.py +++ b/pandas/tests/io/json/test_ujson.py @@ -833,11 +833,14 @@ def test_dataframe(self, orient, numpy): if orient == "records" and numpy: pytest.skip("Not idiomatic pandas") + dtype = np.intp + if numpy is None or orient == "index": + dtype = np.int64 df = DataFrame( [[1, 2, 3], [4, 5, 6]], index=["a", "b"], columns=["x", "y", "z"], - dtype=np.int64, + dtype=dtype, ) encode_kwargs = {} if orient is None else dict(orient=orient) decode_kwargs = {} if numpy is None else dict(numpy=numpy) @@ -900,11 +903,14 @@ def test_dataframe_numpy_labelled(self, orient): tm.assert_frame_equal(output, df) def test_series(self, orient, numpy): + dtype = np.intp + if numpy is None or orient == "index": + dtype = np.int64 s = Series( [10, 20, 30, 40, 50, 60], name="series", index=[6, 7, 8, 9, 10, 15], - dtype=np.int64, + dtype=dtype, ).sort_values() encode_kwargs = {} if orient is None else dict(orient=orient) From 69191ddb12b04f78edce0d91a94936511cb9cf4c Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Mon, 9 Mar 2020 19:24:35 -0700 Subject: [PATCH 5/9] troubleshoot 32bit builds --- pandas/tests/io/json/test_ujson.py | 4 ++++ pandas/tests/series/methods/test_argsort.py | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pandas/tests/io/json/test_ujson.py b/pandas/tests/io/json/test_ujson.py index 61532dabad832..4986ae926eef3 100644 --- a/pandas/tests/io/json/test_ujson.py +++ b/pandas/tests/io/json/test_ujson.py @@ -836,6 +836,8 @@ def test_dataframe(self, orient, numpy): dtype = np.intp if numpy is None or orient == "index": dtype = np.int64 + if numpy is True and orient is None: + dtype = np.int64 df = DataFrame( [[1, 2, 3], [4, 5, 6]], index=["a", "b"], @@ -906,6 +908,8 @@ def test_series(self, orient, numpy): dtype = np.intp if numpy is None or orient == "index": dtype = np.int64 + if numpy is True and orient is None: + dtype = np.int64 s = Series( [10, 20, 30, 40, 50, 60], name="series", diff --git a/pandas/tests/series/methods/test_argsort.py b/pandas/tests/series/methods/test_argsort.py index e0f9027a86f58..4353eb4c8cd64 100644 --- a/pandas/tests/series/methods/test_argsort.py +++ b/pandas/tests/series/methods/test_argsort.py @@ -49,8 +49,8 @@ def test_argsort_stable(self): mexpected = np.argsort(s.values, kind="mergesort") qexpected = np.argsort(s.values, kind="quicksort") - tm.assert_series_equal(mindexer, Series(mexpected)) - tm.assert_series_equal(qindexer, Series(qexpected)) + tm.assert_series_equal(mindexer.astype(np.intp), Series(mexpected)) + tm.assert_series_equal(qindexer.astype(np.intp), Series(qexpected)) msg = ( r"ndarray Expected type , " r"found instead" From 36ab32dfc43a21a26bdd10baa636e6e3d1389a9f Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Tue, 10 Mar 2020 11:53:43 -0700 Subject: [PATCH 6/9] troubleshoot windows builds --- pandas/tests/io/json/test_ujson.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pandas/tests/io/json/test_ujson.py b/pandas/tests/io/json/test_ujson.py index 4986ae926eef3..3f410bd61db7f 100644 --- a/pandas/tests/io/json/test_ujson.py +++ b/pandas/tests/io/json/test_ujson.py @@ -838,6 +838,7 @@ def test_dataframe(self, orient, numpy): dtype = np.int64 if numpy is True and orient is None: dtype = np.int64 + df = DataFrame( [[1, 2, 3], [4, 5, 6]], index=["a", "b"], @@ -865,6 +866,7 @@ def test_dataframe(self, orient, numpy): elif orient == "index": df = df.transpose() + assert (df.dtypes == dtype).all() tm.assert_frame_equal(output, df) def test_dataframe_nested(self, orient): @@ -936,6 +938,7 @@ def test_series(self, orient, numpy): s.name = None s.index = [0, 1, 2, 3, 4, 5] + assert s.dtype == dtype tm.assert_series_equal(output, s) def test_series_nested(self, orient): From 93a6ae967b97f709ce4c0c37efc675e18f124f87 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Tue, 10 Mar 2020 11:54:07 -0700 Subject: [PATCH 7/9] troubleshoot windows builds --- pandas/tests/io/json/test_ujson.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pandas/tests/io/json/test_ujson.py b/pandas/tests/io/json/test_ujson.py index 3f410bd61db7f..cde5d51fdc0c8 100644 --- a/pandas/tests/io/json/test_ujson.py +++ b/pandas/tests/io/json/test_ujson.py @@ -847,8 +847,10 @@ def test_dataframe(self, orient, numpy): ) encode_kwargs = {} if orient is None else dict(orient=orient) decode_kwargs = {} if numpy is None else dict(numpy=numpy) + assert (df.dtypes == dtype).all() output = ujson.decode(ujson.encode(df, **encode_kwargs), **decode_kwargs) + assert (df.dtypes == dtype).all() # Ensure proper DataFrame initialization. if orient == "split": @@ -918,11 +920,13 @@ def test_series(self, orient, numpy): index=[6, 7, 8, 9, 10, 15], dtype=dtype, ).sort_values() + assert s.dtype == dtype encode_kwargs = {} if orient is None else dict(orient=orient) decode_kwargs = {} if numpy is None else dict(numpy=numpy) output = ujson.decode(ujson.encode(s, **encode_kwargs), **decode_kwargs) + assert s.dtype == dtype if orient == "split": dec = _clean_dict(output) From 2a39de949513b00483f370a6764a28d61fd56180 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Tue, 10 Mar 2020 13:17:19 -0700 Subject: [PATCH 8/9] troubleshoot windows builds --- pandas/tests/io/json/test_ujson.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/io/json/test_ujson.py b/pandas/tests/io/json/test_ujson.py index cde5d51fdc0c8..3d47ff8de2f43 100644 --- a/pandas/tests/io/json/test_ujson.py +++ b/pandas/tests/io/json/test_ujson.py @@ -833,7 +833,7 @@ def test_dataframe(self, orient, numpy): if orient == "records" and numpy: pytest.skip("Not idiomatic pandas") - dtype = np.intp + dtype = np.intp if not compat.is_platform_windows() else np.int32 if numpy is None or orient == "index": dtype = np.int64 if numpy is True and orient is None: @@ -909,7 +909,7 @@ def test_dataframe_numpy_labelled(self, orient): tm.assert_frame_equal(output, df) def test_series(self, orient, numpy): - dtype = np.intp + dtype = np.intp if not compat.is_platform_windows() else np.int32 if numpy is None or orient == "index": dtype = np.int64 if numpy is True and orient is None: From 44ddf7a65b435e97dcf3ea7505a77b2aa32cbd2d Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Thu, 12 Mar 2020 10:44:16 -0700 Subject: [PATCH 9/9] refactor --- pandas/tests/io/json/test_ujson.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/pandas/tests/io/json/test_ujson.py b/pandas/tests/io/json/test_ujson.py index 3d47ff8de2f43..e86667626deda 100644 --- a/pandas/tests/io/json/test_ujson.py +++ b/pandas/tests/io/json/test_ujson.py @@ -48,6 +48,18 @@ def numpy(request): return request.param +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(): + dtype = np.int32 + else: + dtype = np.intp + + return dtype + + class TestUltraJSONTests: @pytest.mark.skipif( compat.is_platform_32bit(), reason="not compliant on 32-bit, xref #15865" @@ -833,11 +845,7 @@ def test_dataframe(self, orient, numpy): if orient == "records" and numpy: pytest.skip("Not idiomatic pandas") - dtype = np.intp if not compat.is_platform_windows() else np.int32 - if numpy is None or orient == "index": - dtype = np.int64 - if numpy is True and orient is None: - dtype = np.int64 + dtype = get_int32_compat_dtype(numpy, orient) df = DataFrame( [[1, 2, 3], [4, 5, 6]], @@ -909,11 +917,7 @@ def test_dataframe_numpy_labelled(self, orient): tm.assert_frame_equal(output, df) def test_series(self, orient, numpy): - dtype = np.intp if not compat.is_platform_windows() else np.int32 - if numpy is None or orient == "index": - dtype = np.int64 - if numpy is True and orient is None: - dtype = np.int64 + dtype = get_int32_compat_dtype(numpy, orient) s = Series( [10, 20, 30, 40, 50, 60], name="series",