Skip to content

Commit 23b7f89

Browse files
jbrockmendelSeeminSyed
authored andcommitted
CLN: remove check_series_type (pandas-dev#32513)
1 parent 1ee1ba1 commit 23b7f89

File tree

2 files changed

+25
-35
lines changed

2 files changed

+25
-35
lines changed

pandas/_testing.py

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
is_interval_dtype,
3535
is_list_like,
3636
is_number,
37+
is_numeric_dtype,
3738
is_period_dtype,
3839
is_sequence,
3940
is_timedelta64_dtype,
@@ -1064,7 +1065,6 @@ def assert_series_equal(
10641065
right,
10651066
check_dtype=True,
10661067
check_index_type="equiv",
1067-
check_series_type=True,
10681068
check_less_precise=False,
10691069
check_names=True,
10701070
check_exact=False,
@@ -1085,8 +1085,6 @@ def assert_series_equal(
10851085
check_index_type : bool or {'equiv'}, default 'equiv'
10861086
Whether to check the Index class, dtype and inferred_type
10871087
are identical.
1088-
check_series_type : bool, default True
1089-
Whether to check the Series class is identical.
10901088
check_less_precise : bool or int, default False
10911089
Specify comparison precision. Only used when check_exact is False.
10921090
5 digits (False) or 3 digits (True) after decimal points are compared.
@@ -1118,11 +1116,10 @@ def assert_series_equal(
11181116
# instance validation
11191117
_check_isinstance(left, right, Series)
11201118

1121-
if check_series_type:
1122-
# ToDo: There are some tests using rhs is sparse
1123-
# lhs is dense. Should use assert_class_equal in future
1124-
assert isinstance(left, type(right))
1125-
# assert_class_equal(left, right, obj=obj)
1119+
# TODO: There are some tests using rhs is sparse
1120+
# lhs is dense. Should use assert_class_equal in future
1121+
assert isinstance(left, type(right))
1122+
# assert_class_equal(left, right, obj=obj)
11261123

11271124
# length comparison
11281125
if len(left) != len(right):
@@ -1147,47 +1144,40 @@ def assert_series_equal(
11471144
# is False. We'll still raise if only one is a `Categorical`,
11481145
# regardless of `check_categorical`
11491146
if (
1150-
is_categorical_dtype(left)
1151-
and is_categorical_dtype(right)
1147+
is_categorical_dtype(left.dtype)
1148+
and is_categorical_dtype(right.dtype)
11521149
and not check_categorical
11531150
):
11541151
pass
11551152
else:
11561153
assert_attr_equal("dtype", left, right, obj=f"Attributes of {obj}")
11571154

11581155
if check_exact:
1156+
if not is_numeric_dtype(left.dtype):
1157+
raise AssertionError("check_exact may only be used with numeric Series")
1158+
11591159
assert_numpy_array_equal(
1160-
left._internal_get_values(),
1161-
right._internal_get_values(),
1162-
check_dtype=check_dtype,
1163-
obj=str(obj),
1160+
left._values, right._values, check_dtype=check_dtype, obj=str(obj)
11641161
)
1165-
elif check_datetimelike_compat:
1162+
elif check_datetimelike_compat and (
1163+
needs_i8_conversion(left.dtype) or needs_i8_conversion(right.dtype)
1164+
):
11661165
# we want to check only if we have compat dtypes
11671166
# e.g. integer and M|m are NOT compat, but we can simply check
11681167
# the values in that case
1169-
if needs_i8_conversion(left) or needs_i8_conversion(right):
1170-
1171-
# datetimelike may have different objects (e.g. datetime.datetime
1172-
# vs Timestamp) but will compare equal
1173-
if not Index(left._values).equals(Index(right._values)):
1174-
msg = (
1175-
f"[datetimelike_compat=True] {left._values} "
1176-
f"is not equal to {right._values}."
1177-
)
1178-
raise AssertionError(msg)
1179-
else:
1180-
assert_numpy_array_equal(
1181-
left._internal_get_values(),
1182-
right._internal_get_values(),
1183-
check_dtype=check_dtype,
1168+
1169+
# datetimelike may have different objects (e.g. datetime.datetime
1170+
# vs Timestamp) but will compare equal
1171+
if not Index(left._values).equals(Index(right._values)):
1172+
msg = (
1173+
f"[datetimelike_compat=True] {left._values} "
1174+
f"is not equal to {right._values}."
11841175
)
1185-
elif is_interval_dtype(left) or is_interval_dtype(right):
1176+
raise AssertionError(msg)
1177+
elif is_interval_dtype(left.dtype) or is_interval_dtype(right.dtype):
11861178
assert_interval_array_equal(left.array, right.array)
1187-
elif is_extension_array_dtype(left.dtype) and is_datetime64tz_dtype(left.dtype):
1179+
elif is_datetime64tz_dtype(left.dtype):
11881180
# .values is an ndarray, but ._values is the ExtensionArray.
1189-
# TODO: Use .array
1190-
assert is_extension_array_dtype(right.dtype)
11911181
assert_extension_array_equal(left._values, right._values)
11921182
elif (
11931183
is_extension_array_dtype(left)

pandas/tests/io/pytables/test_store.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2312,7 +2312,7 @@ def test_index_types(self, setup_path):
23122312
values = np.random.randn(2)
23132313

23142314
func = lambda l, r: tm.assert_series_equal(
2315-
l, r, check_dtype=True, check_index_type=True, check_series_type=True
2315+
l, r, check_dtype=True, check_index_type=True
23162316
)
23172317

23182318
with catch_warnings(record=True):

0 commit comments

Comments
 (0)