Skip to content

Commit 4a11161

Browse files
NickCrewsyehoshuadimarsky
authored andcommitted
BUG: Add dropna to Grouper repr (pandas-dev#46754)
1 parent 2575a23 commit 4a11161

File tree

5 files changed

+10
-13
lines changed

5 files changed

+10
-13
lines changed

doc/source/whatsnew/v1.5.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,7 @@ Groupby/resample/rolling
603603
- Bug in :meth:`GroupBy.max` with empty groups and ``uint64`` dtype incorrectly raising ``RuntimeError`` (:issue:`46408`)
604604
- Bug in :meth:`.GroupBy.apply` would fail when ``func`` was a string and args or kwargs were supplied (:issue:`46479`)
605605
- Bug in :meth:`.Rolling.var` would segfault calculating weighted variance when window size was larger than data size (:issue:`46760`)
606+
- Bug in :meth:`Grouper.__repr__` where ``dropna`` was not included. Now it is (:issue:`46754`)
606607

607608
Reshaping
608609
^^^^^^^^^

pandas/core/groupby/grouper.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ class Grouper:
263263
_gpr_index: Index | None
264264
_grouper: Index | None
265265

266-
_attributes: tuple[str, ...] = ("key", "level", "freq", "axis", "sort")
266+
_attributes: tuple[str, ...] = ("key", "level", "freq", "axis", "sort", "dropna")
267267

268268
def __new__(cls, *args, **kwargs):
269269
if kwargs.get("freq") is not None:
@@ -287,6 +287,7 @@ def __init__(
287287
self.freq = freq
288288
self.axis = axis
289289
self.sort = sort
290+
self.dropna = dropna
290291

291292
self.grouper = None
292293
self._gpr_index = None
@@ -295,7 +296,6 @@ def __init__(
295296
self.binner = None
296297
self._grouper = None
297298
self._indexer = None
298-
self.dropna = dropna
299299

300300
@final
301301
@property
@@ -339,7 +339,7 @@ def _get_grouper(
339339
return self.binner, self.grouper, self.obj # type: ignore[return-value]
340340

341341
@final
342-
def _set_grouper(self, obj: NDFrame, sort: bool = False):
342+
def _set_grouper(self, obj: NDFrame, sort: bool = False) -> None:
343343
"""
344344
given an object and the specifications, setup the internal grouper
345345
for this particular specification
@@ -413,7 +413,6 @@ def _set_grouper(self, obj: NDFrame, sort: bool = False):
413413
# "NDFrameT", variable has type "None")
414414
self.obj = obj # type: ignore[assignment]
415415
self._gpr_index = ax
416-
return self._gpr_index
417416

418417
@final
419418
@property

pandas/core/resample.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -1470,14 +1470,14 @@ def __init__(
14701470
self,
14711471
freq="Min",
14721472
closed: Literal["left", "right"] | None = None,
1473-
label: str | None = None,
1473+
label: Literal["left", "right"] | None = None,
14741474
how="mean",
14751475
axis=0,
14761476
fill_method=None,
14771477
limit=None,
14781478
loffset=None,
14791479
kind: str | None = None,
1480-
convention: str | None = None,
1480+
convention: Literal["start", "end", "e", "s"] | None = None,
14811481
base: int | None = None,
14821482
origin: str | TimestampConvertibleTypes = "start_day",
14831483
offset: TimedeltaConvertibleTypes | None = None,
@@ -1523,10 +1523,7 @@ def __init__(
15231523
self.closed = closed
15241524
self.label = label
15251525
self.kind = kind
1526-
1527-
self.convention = convention or "E"
1528-
self.convention = self.convention.lower()
1529-
1526+
self.convention = convention if convention is not None else "e"
15301527
self.how = how
15311528
self.fill_method = fill_method
15321529
self.limit = limit

pandas/tests/groupby/test_groupby.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
def test_repr():
3232
# GH18203
3333
result = repr(Grouper(key="A", level="B"))
34-
expected = "Grouper(key='A', level='B', axis=0, sort=False)"
34+
expected = "Grouper(key='A', level='B', axis=0, sort=False, dropna=True)"
3535
assert result == expected
3636

3737

pandas/tests/resample/test_time_grouper.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -266,15 +266,15 @@ def test_repr():
266266
# GH18203
267267
result = repr(Grouper(key="A", freq="H"))
268268
expected = (
269-
"TimeGrouper(key='A', freq=<Hour>, axis=0, sort=True, "
269+
"TimeGrouper(key='A', freq=<Hour>, axis=0, sort=True, dropna=True, "
270270
"closed='left', label='left', how='mean', "
271271
"convention='e', origin='start_day')"
272272
)
273273
assert result == expected
274274

275275
result = repr(Grouper(key="A", freq="H", origin="2000-01-01"))
276276
expected = (
277-
"TimeGrouper(key='A', freq=<Hour>, axis=0, sort=True, "
277+
"TimeGrouper(key='A', freq=<Hour>, axis=0, sort=True, dropna=True, "
278278
"closed='left', label='left', how='mean', "
279279
"convention='e', origin=Timestamp('2000-01-01 00:00:00'))"
280280
)

0 commit comments

Comments
 (0)