-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
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
BUG: fix convert_dtypes to preserve timezone from tz-aware pyarrow timestamp dtype #60304
Open
road-1
wants to merge
14
commits into
pandas-dev:main
Choose a base branch
from
road-1:60237
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+14
−1
Open
Changes from 2 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
6c99f92
removed if blocks, added test, and added to whats new
road-1 eb5f8cf
Merge branch 'main' into 60237
road-1 b578b6f
added duration if statement
road-1 7d079ac
fixing line length in test file
road-1 cab7b55
re-remove if
road-1 d1bfc53
changing test location
road-1 5ae19ae
changing test location to test_arrow.py
road-1 4cb581d
Merge branch 'main' into 60237
road-1 ae52904
added if statement to pre-existing if statements to check for tz
road-1 67f55f3
simplified if statements
road-1 a96e3fa
Merge branch 'main' into 60237
road-1 adfcf40
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 4422307
Merge branch 'main' into 60237
road-1 f7d5b6a
Merge branch 'main' into 60237
road-1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
By removing this, it will go through
np.dtype(self.pyarrow_dtype.to_pandas_dtype())
, which I think will raise a type error? (becauseto_pandas_dtype
returns a DatetimeTZDtype, andnp.dtype(..)
does not recognize that) And so this will start to return object dtype instead of datetime64?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.
For a bit of context from my linked issue, in pandas 2.0, an ArrowDtype for a pyarrow timestamp with a non-null timezone did return a numpy object dtype
The
if
statements that are removed in this pull request were added in pandas 2.1.0rc0 (#51800) to fix the other issue you pointed out with the datetime unit being lost in older pyarrow versions (fix for that was added in pyarrow 14 apache/arrow#35656). It wasn't noted in the pull request that added them that it was intended to change the semantics for tz-aware types as well, so I think it was just an unintentional side effect that they started returning a numpy dtype of datetime64 instead of object.I noted in the issue that the pyarrow table in the pandas arrays, scalars, and data types section of the API docs seems to indicate that a pyarrow timestamp should map to a pandas DatetimeTZDtype and a numpy datetime64 dtype (which does match how pyarrow itself handles converting a tz-aware array to pandas and numpy respectively)
Quoting from my comment on the issue
You are pretty much exactly the person I had in mind of who would be best suited to make that judgement call. As far as I can tell, a tz-aware pyarrow timestamp is the only instance in that table that can lose information when it maps to the shown numpy dtype