-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
TST: Replace tm.all_index_generator with indices fixture #32886
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 all commits
f65492e
1c9a2bb
737d590
5e09cc3
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 |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
from pandas import MultiIndex, Series, date_range | ||
import pandas._testing as tm | ||
|
||
from ...core.dtypes.generic import ABCMultiIndex | ||
from .test_generic import Generic | ||
|
||
try: | ||
|
@@ -223,15 +224,17 @@ class TestToXArray: | |
and LooseVersion(xarray.__version__) < LooseVersion("0.10.0"), | ||
reason="xarray >= 0.10.0 required", | ||
) | ||
@pytest.mark.parametrize("index", tm.all_index_generator(6)) | ||
def test_to_xarray_index_types(self, index): | ||
def test_to_xarray_index_types(self, indices): | ||
if isinstance(indices, ABCMultiIndex): | ||
pytest.skip("MultiIndex is tested separately") | ||
jreback marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
from xarray import DataArray | ||
|
||
s = Series(range(6), index=index) | ||
s = Series(range(len(indices)), index=indices, dtype="object") | ||
s.index.name = "foo" | ||
result = s.to_xarray() | ||
repr(result) | ||
assert len(result) == 6 | ||
assert len(result) == len(indices) | ||
assert len(result.coords) == 1 | ||
tm.assert_almost_equal(list(result.coords.keys()), ["foo"]) | ||
assert isinstance(result, DataArray) | ||
|
@@ -240,17 +243,9 @@ def test_to_xarray_index_types(self, index): | |
tm.assert_series_equal(result.to_series(), s, check_index_type=False) | ||
|
||
@td.skip_if_no("xarray", min_version="0.7.0") | ||
def test_to_xarray(self): | ||
def test_to_xarray_multiindex(self): | ||
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. Potentially this could benefit from using the MultiIndex cases from |
||
from xarray import DataArray | ||
|
||
s = Series([], dtype=object) | ||
s.index.name = "foo" | ||
result = s.to_xarray() | ||
assert len(result) == 0 | ||
assert len(result.coords) == 1 | ||
tm.assert_almost_equal(list(result.coords.keys()), ["foo"]) | ||
assert isinstance(result, DataArray) | ||
|
||
s = Series(range(6)) | ||
s.index.name = "foo" | ||
s.index = pd.MultiIndex.from_product( | ||
|
@@ -261,3 +256,15 @@ def test_to_xarray(self): | |
tm.assert_almost_equal(list(result.coords.keys()), ["one", "two"]) | ||
assert isinstance(result, DataArray) | ||
tm.assert_series_equal(result.to_series(), s) | ||
|
||
@td.skip_if_no("xarray", min_version="0.7.0") | ||
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. cc @jbrockmendel your test moving PR for xrray might need rebasing after this 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. actually i think we always have a > 0.7.0 xarary? 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 can check that as a follow-up. There are more spots where this condition is used |
||
def test_to_xarray(self): | ||
from xarray import DataArray | ||
|
||
s = Series([], dtype=object) | ||
s.index.name = "foo" | ||
result = s.to_xarray() | ||
assert len(result) == 0 | ||
assert len(result.coords) == 1 | ||
tm.assert_almost_equal(list(result.coords.keys()), ["foo"]) | ||
assert isinstance(result, DataArray) |
Uh oh!
There was an error while loading. Please reload this page.