Skip to content

Commit

Permalink
Add test to ensure that number of bytes of sparse array is correctly
Browse files Browse the repository at this point in the history
reported
  • Loading branch information
hmaarrfk committed Dec 5, 2022
1 parent f934b90 commit a04ba20
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions xarray/tests/test_dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -3259,6 +3259,21 @@ def test_from_series_sparse(self) -> None:
actual_sparse.data = actual_sparse.data.todense()
assert_identical(actual_sparse, actual_dense)

@requires_sparse
def test_sparse_nbytes(self) -> None:
# https://github.com/pydata/xarray/issues/4842#issue-793245791
df = pd.DataFrame()
df["x"] = np.repeat(np.arange(10), 10)
df["y"] = np.repeat(np.arange(10), 10)
df["time"] = np.tile(pd.date_range("2000-01-01", "2000-03-10", freq="W"), 10)
df["rate"] = 10.0
df = df.set_index(["time", "y", "x"])

sparse_ds = xr.Dataset.from_dataframe(df, sparse=True)
rate = sparse_ds["rate"]
assert rate.nbytes < 8000
assert rate.size * rate.dtype.itemsize == 8000

@requires_sparse
def test_from_multiindex_series_sparse(self) -> None:
# regression test for GH4019
Expand Down

0 comments on commit a04ba20

Please sign in to comment.