Skip to content

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

Closed
wants to merge 5 commits into from

Conversation

Vutsuak16
Copy link
Contributor

@Vutsuak16 Vutsuak16 commented Feb 7, 2017

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

Copy link
Member

@jorisvandenbossche jorisvandenbossche left a 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?

@@ -816,14 +816,14 @@ def _check(result, expected):
_check(result, expected)

# tz mismatches
self.assertRaises(TypeError, lambda : dt_tz - ts)
Copy link
Member

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")
Copy link
Member

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?

Copy link
Member

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.

@jorisvandenbossche jorisvandenbossche changed the title Tz uniform ENH: allow timestamp subtraction with different timezones (GH15249) Feb 7, 2017
@jorisvandenbossche jorisvandenbossche added Timezones Timezone data dtype Datetime Datetime data dtype labels Feb 7, 2017
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):
Copy link
Contributor

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.

@sinhrks
Copy link
Member

sinhrks commented Feb 9, 2017

If we allow this, we should also fix related Index and Block ops.

@jreback
Copy link
Contributor

jreback commented Feb 9, 2017

@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.

@jreback
Copy link
Contributor

jreback commented Mar 2, 2017

can you update

@jreback
Copy link
Contributor

jreback commented Apr 3, 2017

closing this as stale, but if you'd like to add more tests / update pls commentt.

@jreback jreback closed this Apr 3, 2017
@jorisvandenbossche jorisvandenbossche added this to the No action milestone Apr 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Datetime Datetime data dtype Timezones Timezone data dtype
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants