-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: assert_frame_equal exception for datetime #37609 #38157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
9eb3e52
09194b2
e5eb45d
96a75a8
2e15617
827efe9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1456,7 +1456,19 @@ def assert_series_equal( | |
check_dtype=check_dtype, | ||
index_values=np.asarray(left.index), | ||
) | ||
elif needs_i8_conversion(left.dtype) or needs_i8_conversion(right.dtype): | ||
elif ( | ||
is_extension_array_dtype(left.dtype) and needs_i8_conversion(right.dtype) | ||
) or (is_extension_array_dtype(right.dtype) and needs_i8_conversion(left.dtype)): | ||
# If we have an extension array and Datetimearray / TimedeltaArray, we still | ||
# want to assert_extension_array_equal even though Datetimearray and | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a lot going on here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You may also want to reference original issue in the comment or docstring (#37609). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay! Will do. |
||
# TimedeltaArray dtypes are not an instance of ExtensionArraydtype subclass | ||
assert_extension_array_equal( | ||
left._values, | ||
right._values, | ||
check_dtype=check_dtype, | ||
index_values=np.asarray(left.index), | ||
) | ||
elif needs_i8_conversion(left.dtype) and needs_i8_conversion(right.dtype): | ||
# DatetimeArray or TimedeltaArray | ||
assert_extension_array_equal( | ||
left._values, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -272,6 +272,12 @@ def test_assert_frame_equal_ignore_extension_dtype_mismatch(right_dtype): | |
tm.assert_frame_equal(left, right, check_dtype=False) | ||
|
||
|
||
def test_assert_frame_equal_datetime_dtype_mismatch(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you parameterize over timedelta, datetime64[ns, UTC], Period[D] |
||
df1 = DataFrame({"a": []}, dtype="datetime64[ns]") | ||
df2 = DataFrame({"a": []}) | ||
tm.assert_frame_equal(df1, df2, check_dtype=False) | ||
|
||
|
||
def test_allows_duplicate_labels(): | ||
left = DataFrame() | ||
right = DataFrame().set_flags(allows_duplicate_labels=False) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not correct, the dtypes of a DTA or TDA are not EA dtypes (well except a tz-aware DTA).
the check is ok, its the text that needs updating.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @jreback !
Thanks for the quick response. Are you saying that just the comment needs to be changed?
Maybe to:
I'm a bit confused otherwise because I say later in the comment that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see my comment again. its not about DTA or TDA themselve, rather their dtypes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jreback
Would this suffice?