Skip to content

Commit

Permalink
Bump datar to 0.15.3 to make np.nanmean and alike work on groupby (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
pwwang committed Oct 10, 2023
1 parent 1d9f216 commit f2ba537
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
14 changes: 14 additions & 0 deletions datar_pandas/api/misc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import warnings

from pipda import register_verb, register_func
from datar.apis.misc import array_ufunc
from datar_numpy.utils import make_array

from ..pandas import DataFrame, Series, PandasObject, SeriesGroupBy
Expand Down Expand Up @@ -206,3 +207,16 @@ def flatten(_data: DataFrame, bycol: bool = False):
if bycol:
return _data.T.values.flatten().tolist()
return _data.values.flatten().tolist()


@array_ufunc.register(SeriesGroupBy, backend="pandas")
def _array_ufunc(x, ufunc, *args, kind, **kwargs):
if kind == "ufunc":
return x.transform(ufunc, *args, **kwargs)

if ufunc.__name__.startswith("nan"):
fun = ufunc.__name__[3:]
kwargs.setdefault("skipna", False)
return x.apply(lambda x: getattr(x, fun)(*args, **kwargs))

return x.apply(ufunc, *args, **kwargs)
18 changes: 9 additions & 9 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ packages = [{include = "datar_pandas"}]
python = "^3.8"
# requires pandas v2+
pdtypes = "^0.2"
datar = "^0.15"
datar = "^0.15.3"
# datar = { path = "../datar" }
datar-numpy = "^0.3.2"
# datar-numpy = { path = "../datar-numpy", extras = ["all"] }
Expand Down

0 comments on commit f2ba537

Please sign in to comment.