Skip to content

Commit 3249b43

Browse files
committed
BUG: Include "dropna" in Grouper._attributes
All this changes I think is that now `dropna` is included in the `__repr__` output. See #46258 for more discussion. And move dropna up out of the "generated" attribute section into the "source" attribute section in the __init__
1 parent f9cdbc6 commit 3249b43

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

doc/source/whatsnew/v1.4.3.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Fixed regressions
2424

2525
Bug fixes
2626
~~~~~~~~~
27-
-
27+
- Include ``dropna`` in ``__repr__`` of a :class:`Grouper` (:issue:`46754`)
2828
-
2929

3030
.. ---------------------------------------------------------------------------

pandas/core/groupby/grouper.py

+2-2
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

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)