-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH: allow timestamp subtraction with different timezones (GH15249) #15329
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are currently not testing that this actually works.
It also seems that you have merge conflicts. Can you ensure that you rebase against the latest master?
pandas/tseries/tests/test_base.py
Outdated
@@ -816,14 +816,14 @@ def _check(result, expected): | |||
_check(result, expected) | |||
|
|||
# tz mismatches | |||
self.assertRaises(TypeError, lambda : dt_tz - ts) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of commenting out those tests, you will need to adapt the test to check that all those cases actually return the correct value
pandas/tslib.pyx
Outdated
if self.tzinfo!="UTC": | ||
self.tz_convert("UTC") | ||
if other.tzinfo!="UTC": | ||
other.tz_convert("UTC") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it is needed to convert both to UTC, as the underlying value (the ones that get subtracted), already are stored as UTC. Can you check that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the conversion is actually needed, you can use _is_utc
.
pandas/tslib.pyx
Outdated
@@ -1052,8 +1056,11 @@ cdef class _Timestamp(datetime): | |||
other = Timestamp(other) | |||
|
|||
# validate tz's | |||
if get_timezone(self.tzinfo) != get_timezone(other.tzinfo): | |||
raise TypeError("Timestamp subtraction must have the same timezones or no timezones") | |||
if get_timezone(self.tzinfo) != get_timezone(other.tzinfo): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not enough, you need to simply do the conversion to 'UTC'. so an already UTC tz will be fine, a non-UTC zone will be converted as well, BUT a non-timezone aware will raise, which should be raised to a higher level.
If we allow this, we should also fix related |
@Vutsuak16 you apparently changed all of the whitespace, so you have a massive diff. Further the most important thing here is to nail down the tests to figure out what is changing. |
can you update |
closing this as stale, but if you'd like to add more tests / update pls commentt. |
works on #15249
passes the relevant tests but fails on few. Those include numpy dependency libgfortran and some environment issues. The output works just fine.
@jreback