-
-
Notifications
You must be signed in to change notification settings - Fork 18.3k
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
TST: add datetimelike tests for tz-aware DatetimeIndex #17694
Changes from all commits
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 |
---|---|---|
|
@@ -34,6 +34,12 @@ def verify_pickle(self, index): | |
unpickled = tm.round_trip_pickle(index) | ||
assert index.equals(unpickled) | ||
|
||
def _fix_tz(self, new_index, orig_index): | ||
if hasattr(orig_index, 'tz'): | ||
assert new_index.tz is None | ||
new_index = new_index.tz_localize('UTC').tz_convert(orig_index.tz) | ||
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. create a new class DatetimeTZ in 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. To clarify, this commit already introduces a new |
||
return new_index | ||
|
||
def test_pickle_compat_construction(self): | ||
# this is testing for pickle compat | ||
if self._holder is None: | ||
|
@@ -278,6 +284,8 @@ def test_ensure_copied_data(self): | |
|
||
index_type = index.__class__ | ||
result = index_type(index.values, copy=True, **init_kwargs) | ||
result = self._fix_tz(result, index) | ||
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. you don't need to touch this because We shold prob refactor this IOW
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.
To sum up:
I can do the suggested refactor though. 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. yes prob need to refactor a bit, |
||
|
||
tm.assert_index_equal(index, result) | ||
tm.assert_numpy_array_equal(index.values, result.values, | ||
check_same='copy') | ||
|
@@ -501,11 +509,13 @@ def test_repeat(self): | |
rep = 2 | ||
i = self.create_index() | ||
expected = pd.Index(i.values.repeat(rep), name=i.name) | ||
expected = self._fix_tz(expected, i) | ||
tm.assert_index_equal(i.repeat(rep), expected) | ||
|
||
i = self.create_index() | ||
rep = np.arange(len(i)) | ||
expected = pd.Index(i.values.repeat(rep), name=i.name) | ||
expected = self._fix_tz(expected, i) | ||
tm.assert_index_equal(i.repeat(rep), expected) | ||
|
||
def test_numpy_repeat(self): | ||
|
@@ -726,7 +736,9 @@ def test_equals(self): | |
assert not idx.equals(np.array(idx)) | ||
|
||
# Cannot pass in non-int64 dtype to RangeIndex | ||
if not isinstance(idx, RangeIndex): | ||
# In tz-aware DatetimeIndex constructor, | ||
# subarr.tz: ValueError: cannot localize from non-UTC data | ||
if not isinstance(idx, RangeIndex) and not hasattr(idx, 'tz'): | ||
same_values = Index(idx, dtype=object) | ||
assert idx.equals(same_values) | ||
assert same_values.equals(idx) | ||
|
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.
really don't spell things like this. rather change
create_index()
to work properly.