Skip to content
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

BUG: assert_series_equal b/w datetime column with equivalent object column fails with check_dtype=False #43707

Closed
3 tasks done
VibhuJawa opened this issue Sep 23, 2021 · 2 comments
Labels
Testing pandas testing functions or related to the test suite Usage Question

Comments

@VibhuJawa
Copy link

VibhuJawa commented Sep 23, 2021

  • 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 master branch of pandas.

Reproducible Example

import pandas  as pd

s1 = pd.Series(['2020-01-01 00:00:00'])
s2 = pd.to_datetime(s1)
pd.testing.assert_series_equal(s1,s2,check_dtype=False)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/nfs/vjawa/pandas/pandas/_testing/asserters.py", line 1078, in assert_series_equal
    _testing.assert_almost_equal(
  File "pandas/_libs/testing.pyx", line 53, in pandas._libs.testing.assert_almost_equal
    cpdef assert_almost_equal(a, b,
  File "pandas/_libs/testing.pyx", line 168, in pandas._libs.testing.assert_almost_equal
    raise_assert_detail(obj, msg, lobj, robj, index_values=index_values)
  File "/home/nfs/vjawa/pandas/pandas/_testing/asserters.py", line 666, in raise_assert_detail
    raise AssertionError(msg)
AssertionError: Series are different

Series values are different (100.0 %)
[index]: [0]
[left]:  [2020-01-01 00:00:00]
[right]: <DatetimeArray>
['2020-01-01 00:00:00']
Length: 1, dtype: datetime64[ns]

Issue Description

BUG: assert_series_equal b/w datetime column with equivalent object column fails with check_dtype=False

When trying to compare two series where one is an object and the other is an equivalent date-time created using pd.to_datetime , we get a unexpected AssertionError.

Expected Behavior

I would expect that we pass the assertion.

Installed Versions

INSTALLED VERSIONS

commit : 36d5c9b
python : 3.9.7.final.0
python-bits : 64
OS : Linux
OS-release : 4.15.0-76-generic
Version : #86-Ubuntu SMP Fri Jan 17 17:24:28 UTC 2020
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.4.0.dev0+745.g36d5c9b8e5
numpy : 1.20.3
pytz : 2021.1
dateutil : 2.8.2
pip : 21.2.4
setuptools : 58.0.4
Cython : 0.29.24
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : 1.3.2
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : 2.7.3
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None

@Xabilahu
Copy link

Xabilahu commented Sep 23, 2021

Assertion fails because inner elements have different classes:
type(s1._values[0]) == <class 'str'> vs type(s2._values[0]) = <class 'pandas._libs.tslibs.timestamps.Timestamp'>

>>> pd._testing.assert_class_equal(s1._values[0], s2._values[0])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/xabi/.conda/envs/nlp/lib/python3.9/site-packages/pandas/_testing/asserters.py", line 459, in assert_class_equal
    raise_assert_detail(obj, msg, repr_class(left), repr_class(right))
  File "/home/xabi/.conda/envs/nlp/lib/python3.9/site-packages/pandas/_testing/asserters.py", line 665, in raise_assert_detail
    raise AssertionError(msg)
AssertionError: Input are different

Input classes are different
[left]:  str
[right]: Timestamp

Classes are checked due to isiterable(s1._values[0]) and not isiterable(s2._values[0]) in testing.pyx:119

@jreback
Copy link
Contributor

jreback commented Sep 23, 2021

check_dtype code is not designed to bypass the entire check otherwise what's the point

@jreback jreback added Testing pandas testing functions or related to the test suite Usage Question and removed Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 23, 2021
@jreback jreback added this to the No action milestone Sep 23, 2021
@jreback jreback closed this as completed Sep 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Testing pandas testing functions or related to the test suite Usage Question
Projects
None yet
Development

No branches or pull requests

3 participants