-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: make tz_localize operate on values rather than categories #28300
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
jreback
merged 12 commits into
pandas-dev:master
from
MarcoGorelli:tz-localize-categories
Nov 2, 2019
+42
−4
Merged
Changes from 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
8d8df82
Operate on categories
MarcoGorelli 98b92cc
remove unused local variable
MarcoGorelli 1c15441
Use __array__ instead of to_list, set dtype in Series
MarcoGorelli 44d22a7
Add tz_convert test
MarcoGorelli 3126408
Rephrase whatsnew entry, move tests
MarcoGorelli c15b457
Remove duplicated tests
3ac3e73
Rephrase whatnew entry
dc9ed3d
Fix conflict
MarcoGorelli 4d0320c
Remove np.asarray, as #28762 has been fixed
9a7f911
Fix rebase
MarcoGorelli 395f04b
Stylistic changes
MarcoGorelli 44a6373
Finish stylistic changes
MarcoGorelli 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -344,6 +344,39 @@ def test_dt_namespace_accessor_categorical(self): | |
expected = Series([2017, 2017, 2018, 2018], name="foo") | ||
tm.assert_series_equal(result, expected) | ||
|
||
def test_dt_tz_localize(self, tz_aware_fixture): | ||
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 add categorical to these test names to indicate what is going onhere. |
||
# GH 27952 | ||
tz = tz_aware_fixture | ||
datetimes = pd.Series( | ||
["2019-01-01", "2019-01-01", "2019-01-02"], dtype="datetime64[ns]" | ||
) | ||
categorical = datetimes.astype("category") | ||
result = categorical.dt.tz_localize(tz) | ||
expected = datetimes.dt.tz_localize(tz) | ||
tm.assert_series_equal(result, expected) | ||
|
||
def test_dt_tz_convert(self, tz_aware_fixture): | ||
# GH 27952 | ||
tz = tz_aware_fixture | ||
datetimes = pd.Series( | ||
["2019-01-01", "2019-01-01", "2019-01-02"], dtype="datetime64[ns, MET]" | ||
) | ||
categorical = datetimes.astype("category") | ||
result = categorical.dt.tz_convert(tz) | ||
expected = datetimes.dt.tz_convert(tz) | ||
tm.assert_series_equal(result, expected) | ||
|
||
@pytest.mark.parametrize("accessor", ["year", "month", "day"]) | ||
def test_dt_other_accessors(self, accessor): | ||
# GH 27952 | ||
datetimes = pd.Series( | ||
["2018-01-01", "2018-01-01", "2019-01-02"], dtype="datetime64[ns]" | ||
) | ||
categorical = datetimes.astype("category") | ||
result = getattr(categorical.dt, accessor) | ||
expected = getattr(datetimes.dt, accessor) | ||
tm.assert_series_equal(result, expected) | ||
|
||
def test_dt_accessor_no_new_attributes(self): | ||
# https://github.com/pandas-dev/pandas/issues/10673 | ||
s = Series(date_range("20130101", periods=5, freq="D")) | ||
|
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.
make this orig.array (doesn't make a practical difference), but is more idiomatic to our usecase here.