Skip to content

ARROW-378: Python: Respect timezone on conversion of Pandas datetime columns - #287

Closed
ahnj wants to merge 1 commit into
apache:masterfrom
ahnj:timestamp-aware
Closed

ahnj wants to merge 1 commit into
apache:masterfrom
ahnj:timestamp-aware

Conversation

@ahnj

@ahnj ahnj commented Jan 14, 2017

Copy link
Copy Markdown

arrow is now pandas datetime timezone aware

Comment thread python/pyarrow/array.pyx Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To my knowledge, all pandas data having a time zone is UTC -- if data is time zone naive, then we may assume UTC in Arrow. I don't think any conversions are necessary here

Comment thread python/pyarrow/array.pyx Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to put this in a Notes section, or in the Sphinx documentation

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my comment above, you can look at x.values.view(np.int64) before and after tz_convert('US/Eastern') to check that the internal values are not modified. If you localize with a non-UTC timestamp, that actually changes the values

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you combine the null and non-null test case?

@wesm wesm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you rebase? Thanks

Comment thread python/pyarrow/array.pyx Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't believe this is necessary.

In [11]: dr = pd.date_range('2000-01-01', periods=10)

In [12]: dr_utc = dr.tz_localize('UTC')

In [13]: dr_utc.values.view(np.int64)
Out[13]: 
array([946684800000000000, 946771200000000000, 946857600000000000,
       946944000000000000, 947030400000000000, 947116800000000000,
       947203200000000000, 947289600000000000, 947376000000000000,
       947462400000000000])

In [14]: dr_utc.tz_convert('US/Eastern').values.view(np.int64)
Out[14]: 
array([946684800000000000, 946771200000000000, 946857600000000000,
       946944000000000000, 947030400000000000, 947116800000000000,
       947203200000000000, 947289600000000000, 947376000000000000,
       947462400000000000])

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops.. now I see what you mean! let me go back and fix, and re-rebase.

@wesm

wesm commented Jan 20, 2017

Copy link
Copy Markdown
Member

Comment thread python/pyarrow/array.pyx Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you revert the code changes in this function?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted and rebased. Thanks.

Comment thread python/pyarrow/array.pyx Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you revise to say "Localized timestamps will currently be returned as UTC (pandas's native representation). Timezone-naive data will be implicitly interpreted as UTC".

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revised with suggested note.

@wesm

wesm commented Jan 22, 2017

Copy link
Copy Markdown
Member

@ahnj can you rebase on the the lastest master? this is based on a commit from 10 days ago https://github.com/ahnj/arrow/commits/timestamp-aware

…columns

new test and docs to enforce and document internal UTC storage of timestamps
and related operations explicit.
@ahnj

ahnj commented Jan 24, 2017 •

Copy link
Copy Markdown
Author

@wesm - rebased with the latest master.

@wesm wesm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1. Thank you for the patience!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants