Skip to content
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

add tests for handling of empty pandas objects in constructors #2735

Merged
merged 2 commits into from
Feb 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions xarray/tests/test_dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -2825,6 +2825,15 @@ def test_to_and_from_series(self):
expected_da,
DataArray.from_series(actual).drop(['x', 'y']))

def test_to_and_from_empty_series(self):
# GH697
expected = pd.Series([])
da = DataArray.from_series(expected)
assert len(da) == 0
actual = da.to_series()
assert len(actual) == 0
assert expected.equals(actual)

def test_series_categorical_index(self):
# regression test for GH700
if not hasattr(pd, 'CategoricalIndex'):
Expand Down
9 changes: 9 additions & 0 deletions xarray/tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2984,6 +2984,15 @@ def test_to_and_from_dataframe(self):
expected = pd.DataFrame([[]], index=idx)
assert expected.equals(actual), (expected, actual)

def test_to_and_from_empty_dataframe(self):
# GH697
expected = pd.DataFrame({'foo': []})
ds = Dataset.from_dataframe(expected)
assert len(ds['foo']) == 0
actual = ds.to_dataframe()
assert len(actual) == 0
assert expected.equals(actual)

def test_from_dataframe_non_unique_columns(self):
# regression test for GH449
df = pd.DataFrame(np.zeros((2, 2)))
Expand Down