-
-
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
Changes from 32 commits
f1d7f59
eeb6201
95b9501
c057358
70b1448
e762ce0
61ca6a8
f9d071a
79bd2eb
f9f413f
ce51e30
37cad4f
39740d8
d1a9cd3
bb8f7b9
b55cced
5bc4b2c
a6c7ec6
a192c66
6d98945
b4ac6aa
a502a04
f06a9e0
5a07736
bae0a30
2f36826
4ebe5b3
0f7cedd
54da03f
4fe7f41
f0fe4e4
8a82832
978b4a3
d44a267
4a1fc86
a6e8681
6b58d2f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,6 +120,10 @@ Other enhancements | |
- ``Styler`` now allows direct CSS class name addition to individual data cells (:issue:`36159`) | ||
- :meth:`Rolling.mean()` and :meth:`Rolling.sum()` use Kahan summation to calculate the mean to avoid numerical problems (:issue:`10319`, :issue:`11645`, :issue:`13254`, :issue:`32761`, :issue:`36031`) | ||
- :meth:`DatetimeIndex.searchsorted`, :meth:`TimedeltaIndex.searchsorted`, :meth:`PeriodIndex.searchsorted`, and :meth:`Series.searchsorted` with datetimelike dtypes will now try to cast string arguments (listlike and scalar) to the matching datetimelike type (:issue:`36346`) | ||
- :meth:`to_json` now implements timezones parsing when orient structure is 'table'. | ||
- :meth:`read_json` now implements timezones parsing when orient structure is 'table'. | ||
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. duplicate note now. |
||
- :meth:`astype` now attempts to convert to 'datetime64[ns, tz]' directly from 'object' with inferred timezone from string (:issue:`35973`). | ||
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. move to datetimelike bug fix |
||
- | ||
|
||
.. _whatsnew_120.api_breaking.python: | ||
|
||
|
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")} | ||
expected = DataFrame(val) | ||
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. call this df |
||
|
||
result = expected.astype({"tz": "datetime64[ns, Europe/Berlin]"}) | ||
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) |
Uh oh!
There was an error while loading. Please reload this page.