-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
split up pandas/tests/indexes/test_multi.py #18644 #21514
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
1888a31
5780b7e
750b8c6
2fb312b
e238b94
7a3753f
baaace3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
… pull request
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ | |
|
||
@pytest.fixture | ||
def idx(): | ||
# a MultiIndex used to test the general functionality of the | ||
# general functionality of this object | ||
major_axis = Index(['foo', 'bar', 'baz', 'qux']) | ||
minor_axis = Index(['one', 'two']) | ||
|
||
|
@@ -24,14 +26,18 @@ def idx(): | |
|
||
@pytest.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. I see that you are iterating over this in a number of tests. why is that? 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. That's more or less a holdover from how the inherited base test class was implemented. I was thinking I'd leave it in case anyone wanted to extend some of these cases with another test multi-index, but yes it looks kind of sloppy. I'll refactor it and remove the duplicate 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. Okay, done with that, but some tests are not relevant to the MultiIndex class or will need to be refactored. I marked those tests with a TODO. The tests that I could refactor have been. 😅 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. yep that's ok. i expect after your refactor will need to go over this again and clean a bit |
||
def index_names(): | ||
# names that match those in the idx fixture for testing equality of | ||
# names assigned to the idx | ||
return ['first', 'second'] | ||
|
||
|
||
@pytest.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. ok w/o using these a leading _ (e.g. holder) is ok |
||
def _holder(): | ||
def holder(): | ||
# the MultiIndex constructor used to base compatibility with pickle | ||
return MultiIndex | ||
|
||
|
||
@pytest.fixture | ||
def _compat_props(): | ||
def compat_props(): | ||
# a MultiIndex must have these properties associated with it | ||
return ['shape', 'ndim', 'size'] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import pytest | ||
|
||
|
||
def test_shift(idx): | ||
|
||
# GH8083 test the base class for shift | ||
pytest.raises(NotImplementedError, idx.shift, 1) | ||
pytest.raises(NotImplementedError, idx.shift, 1, 2) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,12 +87,10 @@ def test_to_hierarchical(): | |
assert result.names == index.names | ||
|
||
|
||
def test_legacy_pickle(): | ||
if PY3: | ||
pytest.skip("testing for legacy pickles not " | ||
"support on py3") | ||
@pytest.mark.skipif(PY3, reason="testing legacy pickles not support on py3") | ||
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. there is an open issue to blow these legacy pickles away |
||
def test_legacy_pickle(datapath): | ||
|
||
path = tm.get_data_path('multiindex_v1.pickle') | ||
path = datapath('indexes', 'multi', 'data', 'multiindex_v1.pickle') | ||
obj = pd.read_pickle(path) | ||
|
||
obj2 = MultiIndex.from_tuples(obj.values) | ||
|
@@ -109,10 +107,10 @@ def test_legacy_pickle(): | |
assert_almost_equal(exp, exp2) | ||
|
||
|
||
def test_legacy_v2_unpickle(): | ||
def test_legacy_v2_unpickle(datapath): | ||
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. same |
||
|
||
# 0.7.3 -> 0.8.0 format manage | ||
path = tm.get_data_path('mindex_073.pickle') | ||
path = datapath('indexes', 'multi', 'data', 'mindex_073.pickle') | ||
obj = pd.read_pickle(path) | ||
|
||
obj2 = MultiIndex.from_tuples(obj.values) | ||
|
@@ -148,3 +146,31 @@ def test_pickle(indices): | |
unpickled = tm.round_trip_pickle(indices) | ||
assert indices.equals(unpickled) | ||
indices.name = original_name | ||
|
||
|
||
def test_to_series(idx): | ||
# assert that we are creating a copy of the index | ||
|
||
s = idx.to_series() | ||
assert s.values is not idx.values | ||
assert s.index is not idx | ||
assert s.name == idx.name | ||
|
||
|
||
def test_to_series_with_arguments(idx): | ||
# GH18699 | ||
|
||
# index kwarg | ||
s = idx.to_series(index=idx) | ||
|
||
assert s.values is not idx.values | ||
assert s.index is idx | ||
assert s.name == idx.name | ||
|
||
# name kwarg | ||
idx = idx | ||
s = idx.to_series(name='__test') | ||
|
||
assert s.values is not idx.values | ||
assert s.index is not idx | ||
assert s.name != idx.name |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from copy import copy, deepcopy | ||
|
||
import pandas.util.testing as tm | ||
from pandas import (CategoricalIndex, IntervalIndex, MultiIndex, PeriodIndex, | ||
|
@@ -111,7 +112,6 @@ def test_ensure_copied_data(idx): | |
|
||
|
||
def test_copy_and_deepcopy(indices): | ||
from copy import copy, deepcopy | ||
|
||
if isinstance(indices, MultiIndex): | ||
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. parameterize and don't need the fixure (it can just be a MI) |
||
return | ||
|
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.
can you add a comment describing the fixture (always do this for fixtures)