Skip to content

Commit

Permalink
fix: use _grouper instead of grouper to dismiss depr warnings sta…
Browse files Browse the repository at this point in the history
…rting pandas 2.2.1
  • Loading branch information
pwwang committed Mar 4, 2024
1 parent daaf8fd commit 028d272
Show file tree
Hide file tree
Showing 28 changed files with 96 additions and 96 deletions.
6 changes: 3 additions & 3 deletions datar_pandas/api/base/arithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def _scale_seriesgroupby(
center=center,
scale_=scale_,
).groupby(
x.grouper,
x._grouper,
sort=x.sort,
dropna=x.dropna,
observed=x.observed,
Expand Down Expand Up @@ -265,7 +265,7 @@ def _pmin_grouped(
out = gf.min(axis=1, skipna=na_rm)
g = gf._datar["grouped"]
return out.groupby(
g.grouper,
g._grouper,
sort=g.sort,
observed=g.observed,
dropna=g.dropna,
Expand Down Expand Up @@ -294,7 +294,7 @@ def _pmax_grouped(
out = gf.max(axis=1, skipna=na_rm)
g = gf._datar["grouped"]
return out.groupby(
g.grouper,
g._grouper,
sort=g.sort,
observed=g.observed,
dropna=g.dropna,
Expand Down
8 changes: 4 additions & 4 deletions datar_pandas/api/base/asis.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def _as_factor_series(x):
@as_factor.register(SeriesGroupBy, backend="pandas")
def _as_factor_series_groupby(x):
return get_obj(x).astype("category").groupby(
x.grouper,
x._grouper,
sort=x.sort,
observed=x.observed,
dropna=x.dropna,
Expand All @@ -169,7 +169,7 @@ def _as_ordered_series(x):
@as_ordered.register(SeriesGroupBy, backend="pandas")
def _as_ordered_series_groupby(x):
return get_obj(x).astype("category").cat.as_ordered().groupby(
x.grouper,
x._grouper,
sort=x.sort,
observed=x.observed,
dropna=x.dropna,
Expand All @@ -194,7 +194,7 @@ def _as_integer_sgb(x: SeriesGroupBy):
out = as_series(out)
out.index = get_obj(x).index
out = out.groupby(
x.grouper,
x._grouper,
sort=x.sort,
observed=x.observed,
dropna=x.dropna,
Expand All @@ -217,7 +217,7 @@ def _is_element(x, y):

if isinstance(x, SeriesGroupBy):
out = x.transform(np.isin, test_elements=y).groupby(
x.grouper,
x._grouper,
observed=x.observed,
sort=x.sort,
dropna=x.dropna,
Expand Down
2 changes: 1 addition & 1 deletion datar_pandas/api/base/factor.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def _factor(
__ast_fallback="normal",
)
return Series(out, index=get_obj(x).index).groupby(
x.grouper,
x._grouper,
observed=x.observed,
sort=x.sort,
dropna=x.dropna,
Expand Down
8 changes: 4 additions & 4 deletions datar_pandas/api/base/seq.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def match_dummy(xx, tab):
sort=table.sort,
dropna=table.dropna,
)
if not _grouper_compatible(x1.grouper, t1.grouper):
if not _grouper_compatible(x1._grouper, t1._grouper):
raise ValueError("Grouping of x and table are not compatible")
df["table"] = get_obj(t1)
elif isinstance(table, Series):
Expand All @@ -91,7 +91,7 @@ def match_dummy(xx, tab):
sort=x1.sort,
dropna=x1.dropna,
)
if not _grouper_compatible(x1.grouper, t1.grouper):
if not _grouper_compatible(x1._grouper, t1._grouper):
df["table"] = [make_array(table)] * df.shape[0]
else:
df["table"] = get_obj(t1)
Expand All @@ -106,7 +106,7 @@ def match_dummy(xx, tab):
.explode()
.astype(int)
).groupby(
x.grouper,
x._grouper,
observed=x.observed,
sort=x.sort,
dropna=x.dropna,
Expand All @@ -129,7 +129,7 @@ def _order_post(out, x, decreasing=False, na_last=True):
out.explode()
.astype(int)
.groupby(
x.grouper,
x._grouper,
observed=x.observed,
sort=x.sort,
dropna=x.dropna,
Expand Down
4 changes: 2 additions & 2 deletions datar_pandas/api/base/string.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def _paste(frame, sep, collapse):
if isinstance(frame, TibbleGrouped):
grouped = frame._datar["grouped"]
out = out.groupby(
grouped.grouper,
grouped._grouper,
sort=grouped.sort,
observed=grouped.observed,
dropna=grouped.dropna,
Expand Down Expand Up @@ -154,7 +154,7 @@ def _sprintf_apply_df(data, bound, exclude, func):
if isinstance(data, TibbleGrouped):
grouped = data._datar["grouped"]
out = out.groupby(
grouped.grouper,
grouped._grouper,
sort=grouped.sort,
observed=grouped.observed,
dropna=grouped.dropna,
Expand Down
2 changes: 1 addition & 1 deletion datar_pandas/api/base/trig.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def _atan2_post(__out, y, x):
return __out

out = __out.groupby(
sgb.grouper,
sgb._grouper,
sort=sgb.sort,
dropna=sgb.dropna,
observed=sgb.observed,
Expand Down
6 changes: 3 additions & 3 deletions datar_pandas/api/dplyr/_rank.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def _row_number(x):
def _(x):
out = x.transform(_row_number)
return out.groupby(
x.grouper,
x._grouper,
observed=x.observed,
sort=x.sort,
dropna=x.dropna,
Expand All @@ -79,7 +79,7 @@ def _(x):
grouped = x._datar["grouped"]
return _row_number(
Series(np.arange(x.shape[0]), index=x.index).groupby(
grouped.grouper,
grouped._grouper,
observed=grouped.observed,
sort=grouped.sort,
dropna=grouped.dropna,
Expand Down Expand Up @@ -177,7 +177,7 @@ def _(x, na_last="keep"):
@_percent_rank.register(GroupBy)
def _(x, na_last="keep"):
ranking = _rank(x, na_last, "min", True).groupby(
x.grouper,
x._grouper,
observed=x.observed,
sort=x.sort,
dropna=x.dropna,
Expand Down
14 changes: 7 additions & 7 deletions datar_pandas/api/dplyr/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ def _n_grouped(_data: TibbleGrouped) -> Data[Int]:
_data = _data._datar.get("summarise_source", _data)
grouped = _data._datar["grouped"]

out = grouped.grouper.size().to_frame().reset_index()
out = grouped._grouper.size().to_frame().reset_index()
out = out.groupby(
grouped.grouper.names,
grouped._grouper.names,
sort=grouped.sort,
observed=grouped.observed,
dropna=grouped.dropna,
Expand All @@ -60,12 +60,12 @@ def _cur_data_all_grouped(_data: TibbleGrouped) -> Series:
grouped = _data._datar["grouped"]
return Series(
[
get_obj(grouped).loc[dict_get(grouped.grouper.groups, key), :]
for key in grouped.grouper.result_index
get_obj(grouped).loc[dict_get(grouped._grouper.groups, key), :]
for key in grouped._grouper.result_index
],
name="cur_data_all",
dtype=object,
index=grouped.grouper.result_index,
index=grouped._grouper.result_index,
)


Expand Down Expand Up @@ -97,7 +97,7 @@ def _cur_group_grouped(_data: TibbleGrouped) -> Series:
out = group_keys(_data, __ast_fallback="normal", __backend="pandas")
# split each row as a df
out = out.apply(lambda row: row.to_frame().T, axis=1)
out.index = _data._datar["grouped"].grouper.result_index
out.index = _data._datar["grouped"]._grouper.result_index
return out


Expand All @@ -109,7 +109,7 @@ def _cur_group_id(_data: DataFrame) -> int:
@cur_group_id.register(TibbleGrouped, context=Context.EVAL, backend="pandas")
def _cur_group_id_grouped(_data: TibbleGrouped) -> Series:
_data = _data._datar.get("summarise_source", _data)
grouper = _data._datar["grouped"].grouper
grouper = _data._datar["grouped"]._grouper
return Series(np.arange(grouper.ngroups), index=grouper.result_index)


Expand Down
2 changes: 1 addition & 1 deletion datar_pandas/api/dplyr/filter_.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def _filter(

grouper = None
if isinstance(_data, TibbleGrouped):
grouper = _data._datar["grouped"].grouper
grouper = _data._datar["grouped"]._grouper

condition = broadcast_to(condition, _data.index, grouper)
if isinstance(condition, np.bool_):
Expand Down
4 changes: 2 additions & 2 deletions datar_pandas/api/dplyr/group_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def _group_keys(_data: DataFrame) -> Tibble:

@group_keys.register(TibbleGrouped, context=Context.EVAL, backend="pandas")
def _group_keys_grouped(_data: TibbleGrouped) -> Tibble:
grouper = _data._datar["grouped"].grouper
grouper = _data._datar["grouped"]._grouper
return Tibble(grouper.result_index.to_frame(index=False), copy=False)


Expand All @@ -79,7 +79,7 @@ def _group_rows_grouped(_data: TibbleGrouped) -> List[List[int]]:

@group_rows.register(GroupBy, context=Context.EVAL, backend="pandas")
def _group_rows_groupby(_data: GroupBy) -> List[List[int]]:
grouper = _data.grouper
grouper = _data._grouper
return [
list(dict_get(grouper.indices, group_key))
for group_key in grouper.result_index
Expand Down
4 changes: 2 additions & 2 deletions datar_pandas/api/dplyr/if_else.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def _if_else_sgb(condition, true, false, missing=None):
get_obj(grouped).iloc[:, 3],
)
return out.groupby(
condition.grouper,
condition._grouper,
observed=condition.observed,
sort=condition.sort,
dropna=condition.dropna,
Expand Down Expand Up @@ -124,7 +124,7 @@ def _case_match(_x, *args, _default=None, _dtypes=None):
return out

return out.groupby(
_x.grouper,
_x._grouper,
observed=_x.observed,
sort=_x.sort,
dropna=_x.dropna,
Expand Down
18 changes: 9 additions & 9 deletions datar_pandas/api/dplyr/slice_.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ def _slice_grouped(
grouped = _data._datar["grouped"]
indices = _sanitize_rows(
rows,
grouped.grouper.indices,
grouped.grouper.result_index,
grouped._grouper.indices,
grouped._grouper.result_index,
)

return _data.take(indices)
Expand Down Expand Up @@ -94,13 +94,13 @@ def _slice_head_grouped(
"""Slice on grouped dataframe"""
grouped = _data._datar["grouped"]
# Calculate n's of each group
ns = grouped.grouper.size().transform(lambda x: _n_from_prop(x, n, prop))
ns = grouped._grouper.size().transform(lambda x: _n_from_prop(x, n, prop))
# Get indices of each group
# A better way?
indices = np.concatenate(
[
grouped.grouper.indices[key][: ns[key]]
for key in grouped.grouper.result_index
grouped._grouper.indices[key][: ns[key]]
for key in grouped._grouper.result_index
]
)

Expand Down Expand Up @@ -148,13 +148,13 @@ def _slice_tail_grouped(
) -> TibbleGrouped:
grouped = _data._datar["grouped"]
# Calculate n's of each group
ns = grouped.grouper.size().transform(lambda x: _n_from_prop(x, n, prop))
ns = grouped._grouper.size().transform(lambda x: _n_from_prop(x, n, prop))
# Get indices of each group
# A better way?
indices = np.concatenate(
[
grouped.grouper.indices[key][-ns[key]:]
for key in grouped.grouper.result_index
grouped._grouper.indices[key][-ns[key]:]
for key in grouped._grouper.result_index
]
)

Expand Down Expand Up @@ -303,7 +303,7 @@ def _sanitize_rows(
if idx.size == 0:
continue

gidx = dict_get(rows.grouper.indices, key)
gidx = dict_get(rows._grouper.indices, key)
out.extend(idx.take(get_obj(rows).take(gidx)))
else:
for key in result_index:
Expand Down
2 changes: 1 addition & 1 deletion datar_pandas/api/dplyr/summarise.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def _summarise_build(
if isinstance(_data, TibbleGrouped):
grouped = _data._datar["grouped"]
outframe = outframe.group_by(
grouped.grouper.names,
grouped._grouper.names,
drop=grouped.observed,
dropna=grouped.dropna,
sort=grouped.sort,
Expand Down
2 changes: 1 addition & 1 deletion datar_pandas/api/forcats/lvl_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def _fct_inorder(_f, ordered: bool = None) -> Categorical:
return out

return Series(out, get_obj(_f).index).groupby(
_f.grouper,
_f._grouper,
observed=_f.observed,
sort=_f.sort,
dropna=_f.dropna,
Expand Down
4 changes: 2 additions & 2 deletions datar_pandas/api/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def __call__(self, *args, **kwds):

try:
return out.groupby(
self.accessor.sgb.grouper,
self.accessor.sgb._grouper,
observed=self.accessor.sgb.observed,
sort=self.accessor.sgb.sort,
dropna=self.accessor.sgb.dropna,
Expand Down Expand Up @@ -143,7 +143,7 @@ def __getattr__(self, name):

try:
return out.groupby(
self.sgb.grouper,
self.sgb._grouper,
observed=self.sgb.observed,
sort=self.sgb.sort,
dropna=self.sgb.dropna,
Expand Down
2 changes: 1 addition & 1 deletion datar_pandas/api/tibble/verbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def _add_column(

grouper = None
if isinstance(_data, TibbleGrouped):
grouper = _data._datar["grouped"].grouper
grouper = _data._datar["grouped"]._grouper
df = broadcast_to(df, _data.index, grouper)
pos = _pos_from_before_after_names(_before, _after, _data.columns.tolist())

Expand Down
2 changes: 1 addition & 1 deletion datar_pandas/api/tidyr/uncount.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def _uncount(
weights = broadcast_to(
weights,
data.index,
None if grouped is None else grouped.grouper,
None if grouped is None else grouped._grouper,
)
if is_scalar(weights):
weights = Series(weights, index=data.index)
Expand Down
Loading

0 comments on commit 028d272

Please sign in to comment.