Skip to content

Commit b535c00

Browse files
committed
BUG: assert_frame_equal exception for datetime
When using assert_frame_equal on two DataFrames that are equal, besides for their dtypes, one dtype being datetime64[ns] and the other not being an extension array, the code raises an exception due to an assertion that checks whether both are extension arrays. This fix addresses issue pandas-dev#37609.
1 parent 65319af commit b535c00

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

pandas/_testing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1456,7 +1456,7 @@ def assert_series_equal(
14561456
check_dtype=check_dtype,
14571457
index_values=np.asarray(left.index),
14581458
)
1459-
elif needs_i8_conversion(left.dtype) or needs_i8_conversion(right.dtype):
1459+
elif needs_i8_conversion(left.dtype) and needs_i8_conversion(right.dtype):
14601460
# DatetimeArray or TimedeltaArray
14611461
assert_extension_array_equal(
14621462
left._values,

pandas/tests/util/test_assert_frame_equal.py

+4
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,10 @@ def test_assert_frame_equal_ignore_extension_dtype_mismatch(right_dtype):
271271
right = DataFrame({"a": [1, 2, 3]}, dtype=right_dtype)
272272
tm.assert_frame_equal(left, right, check_dtype=False)
273273

274+
def test_assert_frame_equal_datetime_dtype_mismatch():
275+
df1 = DataFrame({'a': []}, dtype="datetime64[ns]")
276+
df2 = DataFrame({'a': []})
277+
tm.assert_frame_equal(df1, df2, check_dtype=False)
274278

275279
def test_allows_duplicate_labels():
276280
left = DataFrame()

0 commit comments

Comments
 (0)