-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Rich comparisons of Timestamps raise TypeError instead of returning NotImplemented #24011
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
Comments
Related issue in my library: AlexandreDecan/portion/issues/5 |
Thanks for the small example. If you're interested, you could see if returning NotImplemented there causes any of our tests to fail (probably |
This came up recently for The flip side is that doing this causes inconsistencies in the py2 vs py3 behavior for non-custom types (#23684). |
@jbrockmendel Support for Python 2 will be dropped at the end of the year if I'm right. It's not a big deal (at least to me) to wait until 2019 to see this behaviour "fixed" ;-) @TomAugspurger I can give it a try, but I'm not used to Cython nor to deploy/test libraries with C-extensions. I'll keep you informed of my progress on this. |
With a clean installation of current master branch, two tests errored:
I made the change to return
However, I don't know if I have to do something specific after having changed the code (e.g. building pandas again or something else) ? |
Did you recompile the C extension after making the change? |
No, I didn't. I'm not used to "compile" Python code ;-) Here are the results of
The one that failed is Notice that I simply added if op == Py_EQ:
return False
elif op == Py_NE:
return True
raise TypeError('Cannot compare type %r with type %r' %
(type(self).__name__, type(other).__name__)) With this change, the piece of code I provided in the first post passes. |
I created a PR to get test results from CI. Some of the failing tests are (depending on the chosen build process):
|
Hello,
Problem description
The problem is that pandas'
Timestamp
raisesTypeError
when compared with unsupported types (from pandas' point of view), where I think it should returnNotImplemented
so that comparisons are delegated to the other object (if supported). See https://github.com/pandas-dev/pandas/blob/master/pandas/_libs/tslibs/timestamps.pyx#L247The current behaviour prevents other objects to deal with comparisons with
Timestamp
. For instance, I developed a library that provides arithmetic operations for intervals composed of arbitrary comparable objects. In the context of this library, I defined two specific objects corresponding to negative and positive infinities (that are respectively lower and greater than "everything else"). When these objects are compared with pandas'Timestamp
, aTypeError
is raised, preventing the comparison to be delegated to my "infinities".Code Sample
... raises the following:
Expected Behaviour
TypeError
not raised, assertion holds.Output of
pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 3.5.6.final.0
python-bits: 64
OS: Linux
OS-release: 4.18.17-300.fc29.x86_64
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: fr_BE.UTF-8
LOCALE: fr_BE.UTF-8
pandas: 0.22.0
pytest: 3.7.4
pip: 9.0.3
setuptools: 40.2.0
Cython: None
numpy: 1.14.0
scipy: 1.0.0
pyarrow: None
xarray: None
IPython: 6.2.1
sphinx: None
patsy: None
dateutil: 2.6.1
pytz: 2017.3
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.1.2
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 1.0.1
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
Also tested on the latest 0.23.4.
The text was updated successfully, but these errors were encountered: