Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Fix whatsnew and add tests
  • Loading branch information
reidy-p committed Jun 22, 2018
commit 7408aabd11059608c7949ec1e4a10ebb9fc024a2
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.24.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ Plotting
Groupby/Resample/Rolling
^^^^^^^^^^^^^^^^^^^^^^^^

- Bug in :func:`pandas.core.groupby.first` and :func:`pandas.core.groupby.last` with ``as_index=False`` leading to the loss of timezone information (:issue:`15884`)
- Bug in :func:`pandas.core.groupby.GroupBy.first` and :func:`pandas.core.groupby.GroupBy.last` with ``as_index=False`` leading to the loss of timezone information (:issue:`15884`)
-
-

Expand Down
38 changes: 27 additions & 11 deletions pandas/tests/groupby/test_nth.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,29 +221,38 @@ def test_nth_multi_index(three_group):


@pytest.mark.parametrize('data, expected_first, expected_last', [
({'id': ['A'], 'time': Timestamp('2012-02-01 14:00:00',
tz='US/Central')},
{'id': ['A'], 'time': Timestamp('2012-02-01 14:00:00',
tz='US/Central')},
{'id': ['A'], 'time': Timestamp('2012-02-01 14:00:00',
tz='US/Central')}),
({'id': ['A'],
'time': Timestamp('2012-02-01 14:00:00',
tz='US/Central'),
'foo': [1]},
{'id': ['A'],
'time': Timestamp('2012-02-01 14:00:00',
tz='US/Central'),
'foo': [1]},
{'id': ['A'],
'time': Timestamp('2012-02-01 14:00:00',
tz='US/Central'),
'foo': [1]}),
({'id': ['A', 'B', 'A'],
'time': [Timestamp('2012-01-01 13:00:00',
tz='America/New_York'),
Timestamp('2012-02-01 14:00:00',
tz='US/Central'),
Timestamp('2012-03-01 12:00:00',
tz='Europe/London')]},
tz='Europe/London')],
'foo': [1, 2, 3]},
{'id': ['A', 'B'],
'time': [Timestamp('2012-01-01 13:00:00',
tz='America/New_York'),
Timestamp('2012-02-01 14:00:00',
tz='US/Central')]},
tz='US/Central')],
'foo': [1, 2]},
{'id': ['A', 'B'],
'time': [Timestamp('2012-03-01 12:00:00',
tz='Europe/London'),
Timestamp('2012-02-01 14:00:00',
tz='US/Central')]})
tz='US/Central')],
'foo': [3, 2]})
])
def test_first_last_tz(data, expected_first, expected_last):
# GH15884
Expand All @@ -254,12 +263,19 @@ def test_first_last_tz(data, expected_first, expected_last):

result = df.groupby('id', as_index=False).first()
expected = DataFrame(expected_first)
assert_frame_equal(result, expected)
cols = ['id', 'time', 'foo']
assert_frame_equal(result[cols], expected[cols])

result = df.groupby('id', as_index=False)['time'].first()
assert_frame_equal(result, expected[['id', 'time']])

result = df.groupby('id', as_index=False).last()
expected = DataFrame(expected_last)
assert_frame_equal(result, expected)
cols = ['id', 'time', 'foo']
assert_frame_equal(result[cols], expected[cols])

result = df.groupby('id', as_index=False)['time'].last()
assert_frame_equal(result, expected[['id', 'time']])

def test_nth_multi_index_as_expected():
# PR 9090, related to issue 8979
Expand Down