Skip to content

Commit 3b66021

Browse files
authored
TST: make tests stricter (#32527)
1 parent 011f411 commit 3b66021

13 files changed

+57
-34
lines changed

pandas/tests/arithmetic/test_numeric.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -913,13 +913,13 @@ def test_frame_operators(self, float_frame):
913913

914914
# TODO: taken from tests.series.test_operators; needs cleanup
915915
def test_series_operators(self):
916-
def _check_op(series, other, op, pos_only=False, check_dtype=True):
916+
def _check_op(series, other, op, pos_only=False):
917917
left = np.abs(series) if pos_only else series
918918
right = np.abs(other) if pos_only else other
919919

920920
cython_or_numpy = op(left, right)
921921
python = left.combine(right, op)
922-
tm.assert_series_equal(cython_or_numpy, python, check_dtype=check_dtype)
922+
tm.assert_series_equal(cython_or_numpy, python)
923923

924924
def check(series, other):
925925
simple_ops = ["add", "sub", "mul", "truediv", "floordiv", "mod"]
@@ -942,15 +942,15 @@ def check(series, other):
942942
check(tser, tser[::2])
943943
check(tser, 5)
944944

945-
def check_comparators(series, other, check_dtype=True):
946-
_check_op(series, other, operator.gt, check_dtype=check_dtype)
947-
_check_op(series, other, operator.ge, check_dtype=check_dtype)
948-
_check_op(series, other, operator.eq, check_dtype=check_dtype)
949-
_check_op(series, other, operator.lt, check_dtype=check_dtype)
950-
_check_op(series, other, operator.le, check_dtype=check_dtype)
945+
def check_comparators(series, other):
946+
_check_op(series, other, operator.gt)
947+
_check_op(series, other, operator.ge)
948+
_check_op(series, other, operator.eq)
949+
_check_op(series, other, operator.lt)
950+
_check_op(series, other, operator.le)
951951

952952
check_comparators(tser, 5)
953-
check_comparators(tser, tser + 1, check_dtype=False)
953+
check_comparators(tser, tser + 1)
954954

955955
# TODO: taken from tests.series.test_operators; needs cleanup
956956
def test_divmod(self):

pandas/tests/dtypes/cast/test_construct_from_scalar.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,4 @@ def test_cast_1d_array_like_from_scalar_categorical():
1515
expected = Categorical(["a", "a"], categories=cats)
1616

1717
result = construct_1d_arraylike_from_scalar("a", len(expected), cat_type)
18-
tm.assert_categorical_equal(
19-
result, expected, check_category_order=True, check_dtype=True
20-
)
18+
tm.assert_categorical_equal(result, expected)

pandas/tests/frame/test_constructors.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -916,10 +916,7 @@ def test_constructor_mrecarray(self):
916916
# from GH3479
917917

918918
assert_fr_equal = functools.partial(
919-
tm.assert_frame_equal,
920-
check_index_type=True,
921-
check_column_type=True,
922-
check_frame_type=True,
919+
tm.assert_frame_equal, check_index_type=True, check_column_type=True,
923920
)
924921
arrays = [
925922
("float", np.array([1.5, 2.0])),

pandas/tests/io/excel/test_writers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ def test_float_types(self, np_type, path):
452452
reader = ExcelFile(path)
453453
recons = pd.read_excel(reader, "test1", index_col=0).astype(np_type)
454454

455-
tm.assert_frame_equal(df, recons, check_dtype=False)
455+
tm.assert_frame_equal(df, recons)
456456

457457
@pytest.mark.parametrize("np_type", [np.bool8, np.bool_])
458458
def test_bool_types(self, np_type, path):

pandas/tests/io/json/test_pandas.py

-1
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,6 @@ def test_blocks_compat_GH9037(self):
572572
df_roundtrip,
573573
check_index_type=True,
574574
check_column_type=True,
575-
check_frame_type=True,
576575
by_blocks=True,
577576
check_exact=True,
578577
)

pandas/tests/io/json/test_ujson.py

+31-4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,18 @@ def numpy(request):
4848
return request.param
4949

5050

51+
def get_int32_compat_dtype(numpy, orient):
52+
# See GH#32527
53+
dtype = np.int64
54+
if not ((numpy is None or orient == "index") or (numpy is True and orient is None)):
55+
if compat.is_platform_windows():
56+
dtype = np.int32
57+
else:
58+
dtype = np.intp
59+
60+
return dtype
61+
62+
5163
class TestUltraJSONTests:
5264
@pytest.mark.skipif(
5365
compat.is_platform_32bit(), reason="not compliant on 32-bit, xref #15865"
@@ -833,13 +845,20 @@ def test_dataframe(self, orient, numpy):
833845
if orient == "records" and numpy:
834846
pytest.skip("Not idiomatic pandas")
835847

848+
dtype = get_int32_compat_dtype(numpy, orient)
849+
836850
df = DataFrame(
837-
[[1, 2, 3], [4, 5, 6]], index=["a", "b"], columns=["x", "y", "z"]
851+
[[1, 2, 3], [4, 5, 6]],
852+
index=["a", "b"],
853+
columns=["x", "y", "z"],
854+
dtype=dtype,
838855
)
839856
encode_kwargs = {} if orient is None else dict(orient=orient)
840857
decode_kwargs = {} if numpy is None else dict(numpy=numpy)
858+
assert (df.dtypes == dtype).all()
841859

842860
output = ujson.decode(ujson.encode(df, **encode_kwargs), **decode_kwargs)
861+
assert (df.dtypes == dtype).all()
843862

844863
# Ensure proper DataFrame initialization.
845864
if orient == "split":
@@ -857,7 +876,8 @@ def test_dataframe(self, orient, numpy):
857876
elif orient == "index":
858877
df = df.transpose()
859878

860-
tm.assert_frame_equal(output, df, check_dtype=False)
879+
assert (df.dtypes == dtype).all()
880+
tm.assert_frame_equal(output, df)
861881

862882
def test_dataframe_nested(self, orient):
863883
df = DataFrame(
@@ -897,14 +917,20 @@ def test_dataframe_numpy_labelled(self, orient):
897917
tm.assert_frame_equal(output, df)
898918

899919
def test_series(self, orient, numpy):
920+
dtype = get_int32_compat_dtype(numpy, orient)
900921
s = Series(
901-
[10, 20, 30, 40, 50, 60], name="series", index=[6, 7, 8, 9, 10, 15]
922+
[10, 20, 30, 40, 50, 60],
923+
name="series",
924+
index=[6, 7, 8, 9, 10, 15],
925+
dtype=dtype,
902926
).sort_values()
927+
assert s.dtype == dtype
903928

904929
encode_kwargs = {} if orient is None else dict(orient=orient)
905930
decode_kwargs = {} if numpy is None else dict(numpy=numpy)
906931

907932
output = ujson.decode(ujson.encode(s, **encode_kwargs), **decode_kwargs)
933+
assert s.dtype == dtype
908934

909935
if orient == "split":
910936
dec = _clean_dict(output)
@@ -920,7 +946,8 @@ def test_series(self, orient, numpy):
920946
s.name = None
921947
s.index = [0, 1, 2, 3, 4, 5]
922948

923-
tm.assert_series_equal(output, s, check_dtype=False)
949+
assert s.dtype == dtype
950+
tm.assert_series_equal(output, s)
924951

925952
def test_series_nested(self, orient):
926953
s = Series(

pandas/tests/io/pytables/test_store.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -2298,9 +2298,7 @@ def test_index_types(self, setup_path):
22982298
with catch_warnings(record=True):
22992299
values = np.random.randn(2)
23002300

2301-
func = lambda l, r: tm.assert_series_equal(
2302-
l, r, check_dtype=True, check_index_type=True
2303-
)
2301+
func = lambda l, r: tm.assert_series_equal(l, r, check_index_type=True)
23042302

23052303
with catch_warnings(record=True):
23062304
ser = Series(values, [0, "y"])

pandas/tests/io/test_clipboard.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ def df(request):
7575
)
7676
elif data_type == "mixed":
7777
return DataFrame(
78-
{"a": np.arange(1.0, 6.0) + 0.01, "b": np.arange(1, 6), "c": list("abcde")}
78+
{
79+
"a": np.arange(1.0, 6.0) + 0.01,
80+
"b": np.arange(1, 6).astype(np.int64),
81+
"c": list("abcde"),
82+
}
7983
)
8084
elif data_type == "float":
8185
return tm.makeCustomDataframe(
@@ -146,7 +150,7 @@ class TestClipboard:
146150
def check_round_trip_frame(self, data, excel=None, sep=None, encoding=None):
147151
data.to_clipboard(excel=excel, sep=sep, encoding=encoding)
148152
result = read_clipboard(sep=sep or "\t", index_col=0, encoding=encoding)
149-
tm.assert_frame_equal(data, result, check_dtype=False)
153+
tm.assert_frame_equal(data, result)
150154

151155
# Test that default arguments copy as tab delimited
152156
def test_round_trip_frame(self, df):

pandas/tests/reshape/merge/test_join.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ def test_join_on_inner(self):
298298

299299
expected = df.join(df2, on="key")
300300
expected = expected[expected["value"].notna()]
301-
tm.assert_series_equal(joined["key"], expected["key"], check_dtype=False)
301+
tm.assert_series_equal(joined["key"], expected["key"])
302302
tm.assert_series_equal(joined["value"], expected["value"], check_dtype=False)
303303
tm.assert_index_equal(joined.index, expected.index)
304304

pandas/tests/reshape/test_union_categoricals.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def test_union_categorical(self):
4141
for box in [Categorical, CategoricalIndex, Series]:
4242
result = union_categoricals([box(Categorical(a)), box(Categorical(b))])
4343
expected = Categorical(combined)
44-
tm.assert_categorical_equal(result, expected, check_category_order=True)
44+
tm.assert_categorical_equal(result, expected)
4545

4646
# new categories ordered by appearance
4747
s = Categorical(["x", "y", "z"])

pandas/tests/series/methods/test_argsort.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ def test_argsort_stable(self):
4949
mexpected = np.argsort(s.values, kind="mergesort")
5050
qexpected = np.argsort(s.values, kind="quicksort")
5151

52-
tm.assert_series_equal(mindexer, Series(mexpected), check_dtype=False)
53-
tm.assert_series_equal(qindexer, Series(qexpected), check_dtype=False)
52+
tm.assert_series_equal(mindexer.astype(np.intp), Series(mexpected))
53+
tm.assert_series_equal(qindexer.astype(np.intp), Series(qexpected))
5454
msg = (
5555
r"ndarray Expected type <class 'numpy\.ndarray'>, "
5656
r"found <class 'pandas\.core\.series\.Series'> instead"

pandas/tests/series/methods/test_replace.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ def test_replace_categorical(self, categorical, numeric):
294294
s = pd.Series(categorical)
295295
result = s.replace({"A": 1, "B": 2})
296296
expected = pd.Series(numeric)
297-
tm.assert_series_equal(expected, result, check_dtype=False)
297+
tm.assert_series_equal(expected, result)
298298

299299
def test_replace_categorical_single(self):
300300
# GH 26988

pandas/tests/series/test_duplicates.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ def test_unique():
4747

4848
# GH 18051
4949
s = Series(Categorical([]))
50-
tm.assert_categorical_equal(s.unique(), Categorical([]), check_dtype=False)
50+
tm.assert_categorical_equal(s.unique(), Categorical([]))
5151
s = Series(Categorical([np.nan]))
52-
tm.assert_categorical_equal(s.unique(), Categorical([np.nan]), check_dtype=False)
52+
tm.assert_categorical_equal(s.unique(), Categorical([np.nan]))
5353

5454

5555
def test_unique_data_ownership():

0 commit comments

Comments
 (0)