Skip to content

Commit 0da9d62

Browse files
Joe Hammanshoyer
authored andcommitted
add tests for handling of empty pandas objects in constructors (#2735)
* add tests for GH#697 - handling of empty pandas objects in constructors * make pep8 happy
1 parent a1ff90b commit 0da9d62

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

xarray/tests/test_dataarray.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2872,6 +2872,15 @@ def test_to_and_from_series(self):
28722872
expected_da,
28732873
DataArray.from_series(actual).drop(['x', 'y']))
28742874

2875+
def test_to_and_from_empty_series(self):
2876+
# GH697
2877+
expected = pd.Series([])
2878+
da = DataArray.from_series(expected)
2879+
assert len(da) == 0
2880+
actual = da.to_series()
2881+
assert len(actual) == 0
2882+
assert expected.equals(actual)
2883+
28752884
def test_series_categorical_index(self):
28762885
# regression test for GH700
28772886
if not hasattr(pd, 'CategoricalIndex'):

xarray/tests/test_dataset.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2980,6 +2980,15 @@ def test_to_and_from_dataframe(self):
29802980
expected = pd.DataFrame([[]], index=idx)
29812981
assert expected.equals(actual), (expected, actual)
29822982

2983+
def test_to_and_from_empty_dataframe(self):
2984+
# GH697
2985+
expected = pd.DataFrame({'foo': []})
2986+
ds = Dataset.from_dataframe(expected)
2987+
assert len(ds['foo']) == 0
2988+
actual = ds.to_dataframe()
2989+
assert len(actual) == 0
2990+
assert expected.equals(actual)
2991+
29832992
def test_from_dataframe_non_unique_columns(self):
29842993
# regression test for GH449
29852994
df = pd.DataFrame(np.zeros((2, 2)))

0 commit comments

Comments
 (0)