-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Timestamp subtraction should work for differing timezones #15249
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
we could certainly make this work generally though if someone is trying to subtract different time zones it's an error (they meant to convert) but maybe that's not typical |
@jreback should it be implemented for 'addition operation' too? |
addition of timestamps is not a meaningful operation you will have to handle both sub and rsub |
I am actually now a bit -0 on this as this is a touch too magical. This should be an explicit operation. In reality it doesn't come up that much, so making this a user-explicit operation should not be much of a burden. But will leave the issue open for discussion / implementation. |
closing this, we are moving towards things being very explicit. |
I really don't see any magic here. Every non-naive Contrary to what you said before, subtracting timestamps with different timezones /is/ a valid action that can happen in particular in library code, e.g. if I provide a function If you want to be explicit, what you should not allow is subtraction of naive timestamps, as this gives you essentially random values if the naive timestamps don't happen to be UTC. |
we raise for all comparisons between differing tz's (whether tz is UTC or naive or another zone). this is complicated by the fact that we generally turn strings into naive timestamps, xref xref #18435 subtracting in different timezones would be valid, but is just plain confusing, forcing folks to put things in the same timezone to subtract is not very burdensome and is much much more explicit. |
That is not really true, for comparisons we allow this:
|
see my comment in the linked issue |
I would say that is up for debate. We currently allow it, and I don't think there is anything ambiguous about what the result should be. Why breaking backwards compatibility to start erroring on this? |
Also, the actual issue in the linked comment is about tz-naive vs tz-aware timestamps. Of course neither comparison nor difference make sense if tz-naive timestamps are involved (even naive vs naive dubious, cf. |
They are just time..and should always contain tz info natively,and so they could compare. |
I know this is long closed, but if all of your Timestamps are in the same timezone, why are you squandering cycles on time zones at all? They're only relevant if you have different events in different time zones. |
Code Sample, a copy-pastable example if possible
Problem description
If both timestamps have a timezone specified, the result of this operation is perfectly well-defined. It's quite surprising that I have to riddle my code with
lhs.tz_convert("UTC") - rhs.tz_convert("UTC")
lines to get the difference of timestamps.Expected Output
Output of
pd.show_versions()
pandas: 0.19.2
nose: 1.3.7
pip: 9.0.1
setuptools: 27.2.0
Cython: 0.25.1
numpy: 1.11.2
scipy: None
statsmodels: None
xarray: None
IPython: 5.1.0
sphinx: 1.5.1
patsy: None
dateutil: 2.6.0
pytz: 2016.10
blosc: None
bottleneck: None
tables: None
numexpr: None
matplotlib: None
openpyxl: 2.4.0
xlrd: None
xlwt: None
xlsxwriter: 0.9.6
lxml: None
bs4: None
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.8.1
boto: None
pandas_datareader: None
The text was updated successfully, but these errors were encountered: