-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
TST: Use fixtures instead of setup_method for index tests #28865
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 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,13 +58,14 @@ def test_view(self): | |
tm.assert_index_equal(result, i_view) | ||
|
||
def test_map_callable(self): | ||
expected = self.index + self.index.freq | ||
result = self.index.map(lambda x: x + x.freq) | ||
index = self.create_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. Planning to convert 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. i'm probably not be following the logic correctly, but self.create_index() is a different index to self.index for the datetimelike tests? i.e. tdi
so self.index is created with self.setup_indices() and not the same as
|
||
expected = index + index.freq | ||
result = index.map(lambda x: x + x.freq) | ||
tm.assert_index_equal(result, expected) | ||
|
||
# map to NaT | ||
result = self.index.map(lambda x: pd.NaT if x == self.index[0] else x) | ||
expected = pd.Index([pd.NaT] + self.index[1:].tolist()) | ||
result = index.map(lambda x: pd.NaT if x == index[0] else x) | ||
expected = pd.Index([pd.NaT] + index[1:].tolist()) | ||
tm.assert_index_equal(result, expected) | ||
|
||
@pytest.mark.parametrize( | ||
|
@@ -75,23 +76,24 @@ def test_map_callable(self): | |
], | ||
) | ||
def test_map_dictlike(self, mapper): | ||
expected = self.index + self.index.freq | ||
index = self.create_index() | ||
expected = index + index.freq | ||
|
||
# don't compare the freqs | ||
if isinstance(expected, pd.DatetimeIndex): | ||
expected.freq = None | ||
|
||
result = self.index.map(mapper(expected, self.index)) | ||
result = index.map(mapper(expected, index)) | ||
tm.assert_index_equal(result, expected) | ||
|
||
expected = pd.Index([pd.NaT] + self.index[1:].tolist()) | ||
result = self.index.map(mapper(expected, self.index)) | ||
expected = pd.Index([pd.NaT] + index[1:].tolist()) | ||
result = index.map(mapper(expected, index)) | ||
tm.assert_index_equal(result, expected) | ||
|
||
# empty map; these map to np.nan because we cannot know | ||
# to re-infer things | ||
expected = pd.Index([np.nan] * len(self.index)) | ||
result = self.index.map(mapper([], [])) | ||
expected = pd.Index([np.nan] * len(index)) | ||
result = index.map(mapper([], [])) | ||
tm.assert_index_equal(result, expected) | ||
|
||
def test_asobject_deprecated(self): | ||
|
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.
maybe a smaller diff if the fixture was named index?
Not just this PR, but in general maybe we shouldn't use the plural when creating fixtures since when the fixture is used it creates a single value at a time and so the plural name in the tests can sometimes be confusing.