-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
ENH: implement timeszones support for read_json(orient='table') and astype() from 'object' #35973
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
Merged
Merged
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
f1d7f59
ENH: implement timeszones support for DataFrame.to_json(orient='table')
attack68 eeb6201
pep8
attack68 95b9501
minor cleanup
attack68 c057358
linting and type cleanup
attack68 70b1448
isort
attack68 e762ce0
static type ignore
attack68 61ca6a8
black and mypy fix to work together
attack68 f9d071a
re-write so conversion occurs in astype() as opposed to parse_json()
attack68 79bd2eb
removed unused imports
attack68 f9f413f
black fix
attack68 ce51e30
typing
attack68 37cad4f
astype conversion for objects of one tz to another tz
attack68 39740d8
linting isort
attack68 d1a9cd3
move tests
attack68 bb8f7b9
move tests
attack68 b55cced
seg fault failure fix?
attack68 5bc4b2c
remove raise condition
attack68 a6c7ec6
eliminate try-except and move tests
attack68 a192c66
black fix
attack68 6d98945
issues stamp
attack68 b4ac6aa
linting
attack68 a502a04
Merge remote-tracking branch 'upstream/master' into enh_timezones_json
attack68 f06a9e0
Merge remote-tracking branch 'upstream/master' into enh_timezones_json
attack68 5a07736
Merge remote-tracking branch 'upstream/master' into enh_timezones_json
attack68 bae0a30
test common terms
attack68 2f36826
test common terms
attack68 4ebe5b3
Merge remote-tracking branch 'upstream/master' into enh_timezones_json
attack68 0f7cedd
Merge remote-tracking branch 'upstream/master' into enh_timezones_json
attack68 54da03f
uncomment previous test now working.
attack68 4fe7f41
double quotes error
attack68 f0fe4e4
restart tests
attack68 8a82832
restart tests
attack68 978b4a3
Merge remote-tracking branch 'upstream/master' into enh_timezones_json
attack68 d44a267
fix whats new comments
attack68 4a1fc86
rephrased test
attack68 a6e8681
Merge remote-tracking branch 'upstream/master' into enh_timezones_json
attack68 6b58d2f
Merge branch 'master' into enh_timezones_json
jreback 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -587,3 +587,27 @@ def test_astype_ignores_errors_for_extension_dtypes(self, df, errors): | |
msg = "(Cannot cast)|(could not convert)" | ||
with pytest.raises((ValueError, TypeError), match=msg): | ||
df.astype(float, errors=errors) | ||
|
||
def test_astype_tz_conversion(self): | ||
jreback marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# GH 35973 | ||
val = {"tz": date_range("2020-08-30", freq="d", periods=2, tz="Europe/London")} | ||
df = DataFrame(val) | ||
result = df.astype({"tz": "datetime64[ns, Europe/Berlin]"}) | ||
|
||
expected = df | ||
expected["tz"] = expected["tz"].dt.tz_convert("Europe/Berlin") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you move this expected change to L595 as it goes with it |
||
tm.assert_frame_equal(result, expected) | ||
|
||
@pytest.mark.parametrize("tz", ["UTC", "Europe/Berlin"]) | ||
def test_astype_tz_object_conversion(self, tz): | ||
# GH 35973 | ||
val = {"tz": date_range("2020-08-30", freq="d", periods=2, tz="Europe/London")} | ||
expected = DataFrame(val) | ||
|
||
# convert expected to object dtype from other tz str (independently tested) | ||
result = expected.astype({"tz": f"datetime64[ns, {tz}]"}) | ||
result = result.astype({"tz": "object"}) | ||
|
||
# do real test: object dtype to a specified tz, different from construction tz. | ||
result = result.astype({"tz": "datetime64[ns, Europe/London]"}) | ||
tm.assert_frame_equal(result, expected) |
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.