pandas-dev/pandas

BUG: assert_frame_equal fails with AttributeError: 'numpy.dtype[datetime64]' object has no attribute 'unit'

MichaelSkralivetsky opened this issue · 1 comments

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

pd.testing.assert_frame_equal(df1, df2,check_dtype=False, check_index_type=True, 	check_column_type=True, check_like=True, 	check_names=True)

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[4], line 1
----> 1 pd.testing.assert_frame_equal(df1, df2,check_dtype=False, check_index_type=True, 	check_column_type=True, check_like=True, 	check_names=True)

    [... skipping hidden 2 frame]

File ~/.pythonlibs/mlrun-base/lib/python3.9/site-packages/pandas/_testing/asserters.py:744, in assert_extension_array_equal(left, right, check_dtype, index_values, check_exact, rtol, atol, obj)
    742     l_unit = np.datetime_data(left.dtype)[0]
    743 if not isinstance(right.dtype, np.dtype):
--> 744     r_unit = cast(DatetimeTZDtype, left.dtype).unit
    745 else:
    746     r_unit = np.datetime_data(right.dtype)[0]

AttributeError: 'numpy.dtype[datetime64]' object has no attribute 'unit'
df1.info()

<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 1 entries, 2023-10-27 14:06:58.676000 to 2023-10-27 14:06:58.676000
Data columns (total 14 columns):
 #   Column    Non-Null Count  Dtype         
---  ------    --------------  -----         
 0   sqtqgbqm  1 non-null      datetime64[ns]
 1   mcmfkyrs  1 non-null      int64         
 2   oskqswod  1 non-null      object        
 3   ojeqkjzl  1 non-null      float64       
 4   qivwugqn  1 non-null      object        
 5   qdgeasmh  1 non-null      datetime64[ns]
 6   goqnadhx  1 non-null      float64       
 7   okhvlsdx  1 non-null      object        
 8   pzbghlrm  1 non-null      float64       
 9   lyjyrloj  1 non-null      bool          
 10  fzjywihu  1 non-null      datetime64[ns]
 11  ojvflgwl  1 non-null      int64         
 12  ostdkxcu  1 non-null      object        
 13  hfchppxa  1 non-null      float64       
dtypes: bool(1), datetime64[ns](3), float64(4), int64(2), object(4)
memory usage: 113.0+ bytes
df2.info()

<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 1 entries, 2023-10-27 14:06:58.676000 to 2023-10-27 14:06:58.676000
Data columns (total 14 columns):
 #   Column    Non-Null Count  Dtype              
---  ------    --------------  -----              
 0   sqtqgbqm  1 non-null      datetime64[ns, UTC]
 1   mcmfkyrs  1 non-null      int64              
 2   oskqswod  1 non-null      object             
 3   ojeqkjzl  1 non-null      float64            
 4   qivwugqn  1 non-null      bool               
 5   qdgeasmh  1 non-null      datetime64[ns, UTC]
 6   goqnadhx  1 non-null      float64            
 7   okhvlsdx  1 non-null      object             
 8   pzbghlrm  1 non-null      float64            
 9   lyjyrloj  1 non-null      bool               
 10  fzjywihu  1 non-null      datetime64[ns, UTC]
 11  ojvflgwl  1 non-null      int64              
 12  ostdkxcu  1 non-null      object             
 13  hfchppxa  1 non-null      float64            
dtypes: bool(2), datetime64[ns, UTC](3), float64(4), int64(2), object(3)
memory usage: 106.0+ bytes


### Issue Description

assert_frame_equal fails like this with pandas 2.1.2 and does not fail with pandas 2.0.0

### Expected Behavior

assert_frame_equal should not fail

### Installed Versions

INSTALLED VERSIONS
------------------
commit              : a60ad39b4a9febdea9a59d602dad44b1538b0ea5
python              : 3.9.16.final.0
python-bits         : 64
OS                  : Linux
OS-release          : 3.10.0-1160.88.1.el7.x86_64
Version             : #1 SMP Tue Mar 7 15:41:52 UTC 2023
machine             : x86_64
processor           : x86_64
byteorder           : little
LC_ALL              : None
LANG                : C.UTF-8
LOCALE              : en_US.UTF-8

pandas              : 2.1.2
numpy               : 1.22.4
pytz                : 2023.3.post1
dateutil            : 2.8.2
setuptools          : 68.2.2
pip                 : 22.3.1
Cython              : None
pytest              : None
hypothesis          : None
sphinx              : None
blosc               : None
feather             : None
xlsxwriter          : None
lxml.etree          : None
html5lib            : None
pymysql             : 1.0.2
psycopg2            : None
jinja2              : 3.1.2
IPython             : 8.11.0
pandas_datareader   : None
bs4                 : 4.12.2
bottleneck          : None
dataframe-api-compat: None
fastparquet         : None
fsspec              : 2023.1.0
gcsfs               : 2023.1.0
matplotlib          : 3.5.2
numba               : None
numexpr             : None
odfpy               : None
openpyxl            : None
pandas_gbq          : None
pyarrow             : 11.0.0
pyreadstat          : None
pyxlsb              : None
s3fs                : 2023.1.0
scipy               : 1.11.3
sqlalchemy          : 1.4.49
tables              : None
tabulate            : 0.8.10
xarray              : None
xlrd                : None
zstandard           : None
tzdata              : 2023.3
qtpy                : None
pyqt5               : None