Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
03ee26b
Added test coverage for observed=False with ops
WillAyd May 15, 2019
ee549ed
Fixed issue with observed=False and nth
WillAyd May 15, 2019
f0a510d
Stubbed whatsnew note
WillAyd May 15, 2019
f671204
Merge remote-tracking branch 'upstream/master' into nth-na-handling
WillAyd May 16, 2019
94dda01
Merge remote-tracking branch 'upstream/master' into nth-na-handling
WillAyd May 17, 2019
e59a991
lint fixup
WillAyd May 17, 2019
3677471
Simplified test
WillAyd May 19, 2019
34c2f06
Merge remote-tracking branch 'upstream/master' into nth-na-handling
WillAyd May 19, 2019
2ca34e3
whatsnew whitespace fix
WillAyd May 19, 2019
d3e5efa
Merge remote-tracking branch 'upstream/master' into nth-na-handling
WillAyd Jun 3, 2019
f9758b8
Merge remote-tracking branch 'upstream/master' into nth-na-handling
WillAyd Jun 4, 2019
ad729c5
Merge remote-tracking branch 'upstream/master' into nth-na-handling
WillAyd Jun 27, 2019
5b7b6bc
Merge remote-tracking branch 'upstream/master' into nth-na-handling
WillAyd Jul 15, 2019
aff7327
Merge remote-tracking branch 'upstream/master' into nth-na-handling
WillAyd Jul 15, 2019
47201fb
blackify
WillAyd Jul 15, 2019
56822cc
Merge remote-tracking branch 'upstream/master' into nth-na-handling
WillAyd Jul 15, 2019
1804e27
Removed doc whitespace
WillAyd Jul 15, 2019
4c2e413
Merge remote-tracking branch 'upstream/master' into nth-na-handling
WillAyd Jul 25, 2019
a837564
moved whatsnew to 0.25.1
WillAyd Jul 25, 2019
308e569
Merge remote-tracking branch 'upstream/master' into WillAyd-nth-na-ha…
TomAugspurger Aug 19, 2019
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
blackify
  • Loading branch information
WillAyd committed Jul 15, 2019
commit 47201fb6ccf6eac0f40c0f18efd6ee2876e7d27f
3 changes: 1 addition & 2 deletions pandas/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -1774,8 +1774,7 @@ def nth(self, n: Union[int, List[int]], dropna: Optional[str] = None) -> DataFra
result_index = self.grouper.result_index
out.index = result_index[ids[mask]]

if not self.observed and isinstance(
result_index, CategoricalIndex):
if not self.observed and isinstance(result_index, CategoricalIndex):
out = out.reindex(result_index)

return out.sort_index() if self.sort else out
Expand Down
12 changes: 6 additions & 6 deletions pandas/tests/groupby/test_categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,15 +433,15 @@ def test_observed_groups_with_nan(observed):

def test_observed_nth():
# GH 26385
cat = pd.Categorical(['a', np.nan, np.nan], categories=['a', 'b', 'c'])
cat = pd.Categorical(["a", np.nan, np.nan], categories=["a", "b", "c"])
ser = pd.Series([1, 2, 3])
df = pd.DataFrame({'cat': cat, 'ser': ser})
df = pd.DataFrame({"cat": cat, "ser": ser})

result = df.groupby('cat', observed=False)['ser'].nth(0)
result = df.groupby("cat", observed=False)["ser"].nth(0)

index = pd.Categorical(['a', 'b', 'c'], categories=['a', 'b', 'c'])
expected = pd.Series([1, np.nan, np.nan], index=index, name='ser')
expected.index.name = 'cat'
index = pd.Categorical(["a", "b", "c"], categories=["a", "b", "c"])
expected = pd.Series([1, np.nan, np.nan], index=index, name="ser")
expected.index.name = "cat"

tm.assert_series_equal(result, expected)

Expand Down