Skip to content

ENH: assert_frame_equal to show column name for columns of dtype datetime64[ns] #43457

@roger-yu-ds

Description

@roger-yu-ds

Is your feature request related to a problem?

I wish I could use pandas.testing.assert_frame_equal to determine which of my datetime64[ns] columns are not equal when comparing two dataframes. Currently the output is AssertionError: numpy array are different without indicating which columns are different.

Describe the solution you'd like

When two dataframes with datetime64[ns] columns are compared using pandas.testing.assert_frame_equal and there are different values, the output should also have the column name that has this difference, e.g. AssertionError: DataFrame.iloc[:, 1] (column name="b") are different.

Additional context

Minimal reproducible code below. If you change one of the datetime values to an integer, the dtype of the column will be object, in which case, the desired behaviour is shown.

import pandas as pd
from pandas.testing import assert_frame_equal

df_left = pd.DataFrame({'a': [1, 2], 'b': [
    datetime(2021, 1, 1), 
#     1,
    datetime(2021, 1, 2)
]})
df_right = pd.DataFrame({'a': [1, 2], 'b': [
    datetime(2021, 1, 1), 
#     1,
    datetime(2021, 1, 3)
]})

assert_frame_equal(left=df_left, right=df_right)

Metadata

Metadata

Assignees

No one assigned

    Labels

    DatetimeDatetime data dtypeEnhancementError ReportingIncorrect or improved errors from pandasTestingpandas testing functions or related to the test suite

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions