-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
TST: Use indices fixture in tests/indexes/test_base.py #32963
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 3 commits
6ae9bd2
8ed190d
1eba26d
9da6c64
2a3e611
830f12d
4c88220
85328aa
a6fed52
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 |
---|---|---|
|
@@ -33,7 +33,6 @@ | |
period_range, | ||
) | ||
import pandas._testing as tm | ||
from pandas.conftest import indices_dict | ||
from pandas.core.indexes.api import ( | ||
Index, | ||
MultiIndex, | ||
|
@@ -47,18 +46,6 @@ | |
class TestIndex(Base): | ||
_holder = Index | ||
|
||
@pytest.fixture | ||
def index(self, request): | ||
""" | ||
Fixture for selectively parametrizing indices_dict via indirect parametrization | ||
(parametrize over indices_dict keys with indirect=True). Defaults to string | ||
index if no keys are provided. | ||
""" | ||
key = getattr(request, "param", "string") | ||
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. This line makes that using 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. Thanks @SaturnFromTitan for doing this. This was intended to be a follow-up to #28865 #28865 (comment) 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. This is now replaced by |
||
|
||
# copy to avoid mutation, e.g. setting .name | ||
return indices_dict[key].copy() | ||
|
||
def create_index(self) -> Index: | ||
return Index(list("abcde")) | ||
|
||
|
@@ -83,13 +70,15 @@ def test_copy_and_deepcopy(self, index): | |
def test_constructor_regular(self, indices): | ||
tm.assert_contains_all(indices, indices) | ||
|
||
@pytest.mark.parametrize("index", ["string"], indirect=True) | ||
def test_constructor_casting(self, index): | ||
# casting | ||
arr = np.array(index) | ||
new_index = Index(arr) | ||
tm.assert_contains_all(arr, new_index) | ||
tm.assert_index_equal(index, new_index) | ||
|
||
@pytest.mark.parametrize("index", ["string"], indirect=True) | ||
def test_constructor_copy(self, index): | ||
# copy | ||
# index = self.create_index() | ||
|
@@ -640,6 +629,7 @@ def test_nanosecond_index_access(self): | |
expected_ts = np_datetime64_compat("2013-01-01 00:00:00.000000050+0000", "ns") | ||
assert first_value == x[Timestamp(expected_ts)] | ||
|
||
@pytest.mark.parametrize("index", ["string"], indirect=True) | ||
def test_booleanindex(self, index): | ||
bool_index = np.ones(len(index), dtype=bool) | ||
bool_index[5:30:2] = False | ||
|
@@ -681,6 +671,7 @@ def test_empty_fancy_raises(self, index): | |
with pytest.raises(IndexError, match=msg): | ||
index[empty_farr] | ||
|
||
@pytest.mark.parametrize("index", ["string"], indirect=True) | ||
def test_intersection(self, index, sort): | ||
first = index[:20] | ||
second = index[:10] | ||
|
@@ -712,6 +703,7 @@ def test_intersection_name_preservation(self, index2, keeps_name, sort): | |
assert result.name == expected.name | ||
tm.assert_index_equal(result, expected) | ||
|
||
@pytest.mark.parametrize("index", ["string"], indirect=True) | ||
@pytest.mark.parametrize( | ||
"first_name,second_name,expected_name", | ||
[("A", "A", "A"), ("A", "B", None), (None, "B", None)], | ||
|
@@ -790,6 +782,7 @@ def test_chained_union(self, sort): | |
expected = j1.union(j2, sort=sort).union(j3, sort=sort) | ||
tm.assert_index_equal(union, expected) | ||
|
||
@pytest.mark.parametrize("index", ["string"], indirect=True) | ||
def test_union(self, index, sort): | ||
first = index[5:20] | ||
second = index[:10] | ||
|
@@ -827,6 +820,7 @@ def test_union_sort_special_true(self, slice_): | |
tm.assert_index_equal(result, expected) | ||
|
||
@pytest.mark.parametrize("klass", [np.array, Series, list]) | ||
@pytest.mark.parametrize("index", ["string"], indirect=True) | ||
def test_union_from_iterables(self, index, klass, sort): | ||
# GH 10149 | ||
first = index[5:20] | ||
|
@@ -839,6 +833,7 @@ def test_union_from_iterables(self, index, klass, sort): | |
tm.assert_index_equal(result, everything.sort_values()) | ||
assert tm.equalContents(result, everything) | ||
|
||
@pytest.mark.parametrize("index", ["string"], indirect=True) | ||
def test_union_identity(self, index, sort): | ||
first = index[5:20] | ||
|
||
|
@@ -1009,6 +1004,7 @@ def test_append_empty_preserve_name(self, name, expected): | |
result = left.append(right) | ||
assert result.name == expected | ||
|
||
@pytest.mark.parametrize("index", ["string"], indirect=True) | ||
@pytest.mark.parametrize("second_name,expected", [(None, None), ("name", "name")]) | ||
def test_difference_name_preservation(self, index, second_name, expected, sort): | ||
first = index[5:20] | ||
|
@@ -1026,22 +1022,25 @@ def test_difference_name_preservation(self, index, second_name, expected, sort): | |
else: | ||
assert result.name == expected | ||
|
||
@pytest.mark.parametrize("index", ["string"], indirect=True) | ||
def test_difference_empty_arg(self, index, sort): | ||
first = index[5:20] | ||
first.name == "name" | ||
first.name = "name" | ||
result = first.difference([], sort) | ||
|
||
assert tm.equalContents(result, first) | ||
assert result.name == first.name | ||
|
||
@pytest.mark.parametrize("index", ["string"], indirect=True) | ||
def test_difference_identity(self, index, sort): | ||
first = index[5:20] | ||
first.name == "name" | ||
first.name = "name" | ||
result = first.difference(first, sort) | ||
|
||
assert len(result) == 0 | ||
assert result.name == first.name | ||
|
||
@pytest.mark.parametrize("index", ["string"], indirect=True) | ||
def test_difference_sort(self, index, sort): | ||
first = index[5:20] | ||
second = index[:10] | ||
|
@@ -1867,6 +1866,7 @@ def test_boolean_cmp(self, values): | |
|
||
tm.assert_numpy_array_equal(result, expected) | ||
|
||
@pytest.mark.parametrize("index", ["string"], indirect=True) | ||
@pytest.mark.parametrize("name,level", [(None, 0), ("a", "a")]) | ||
def test_get_level_values(self, index, name, level): | ||
expected = index.copy() | ||
|
Uh oh!
There was an error while loading. Please reload this page.