Skip to content

Commit

Permalink
Provide abstract .Quantity.to_series()
Browse files Browse the repository at this point in the history
  • Loading branch information
khaeru committed Mar 8, 2021
1 parent a14b993 commit 55a2b15
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
8 changes: 8 additions & 0 deletions doc/whatsnew.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ What's new
.. Next release
.. ============
v1.2.1 (2021-03-08)
===================

Bug fixes
---------

- Provide abstract :class:`.Quantity.to_series` method for type checking in packages that depend on :mod:`genno`.

v1.2.0 (2021-03-08)
===================

Expand Down
8 changes: 7 additions & 1 deletion genno/core/quantity.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,16 @@ def __new__(cls, *args, **kwargs):
# Use _get_class() to retrieve either AttrSeries or SparseDataArray
return object.__new__(Quantity._get_class(cls))

def to_series(self) -> pd.Series:
"""Like :meth:`xarray.DataArray.to_series`."""
# Provided only for type-checking in other packages. AttrSeries implements;
# SparseDataArray uses the xr.DataArray method.
raise RuntimeError

@classmethod
def from_series(cls, series, sparse=True):
"""Convert `series` to the Quantity class given by :data:`.CLASS`."""
# NB signature is the same as xr.DataArray.from_series()
# NB signature is the same as xr.DataArray.from_series(); except sparse=True
assert sparse
return cls._get_class().from_series(series, sparse)

Expand Down

0 comments on commit 55a2b15

Please sign in to comment.