首页 > 解决方案 > Getting AssertionError: (None, <10 * Seconds>) when comparing two "seemingly" identical dataframes

问题描述

Trying to create a mock data frame for an assertion. I have verified that the two data frames have the same dtypes and are both DateTimeIndex. However the Assertion fails with this:

Traceback (most recent call last):
tests/test_helpers.py line 143 in test_get_n_sec_metrics
  assert_frame_equal(expected,actual)
lib/python3.8/site-packages/pandas/_testing.py line 1704 in assert_frame_equal
  assert_series_equal(
lib/python3.8/site-packages/pandas/_testing.py line 1389 in assert_series_equal
  assert lidx.freq == ridx.freq, (lidx.freq, ridx.freq) AssertionError: (None, <10 * Seconds>)

Which I interpret as the two df's having a mismatch in the frequency between the tested dataframe and my mock dataframe.

Here is my mock:

df_expected = pd.DataFrame({
            'date':['2019-02-07 21:11:00','2019-02-07 21:11:10','2019-02-07 21:11:20'],
            'letters':['a','b','c'],
            'counts':[1,2,3],
        })
df_expected['date']=pd.to_datetime(df_expected['date'])
df_expected.set_index('date', inplace=True)
df_expected.index.freq='10s'

Asking for a friend.

标签: pythonpandas

解决方案


好吧,没关系找到答案。这解决了它:

在行 df_expected.index.freq='10s' 切换10s10S


推荐阅读