Skip to content

TST: Stateful/Wrong Test test_agg_timezone_round_trip #26864

Closed
@jbrockmendel

Description

@jbrockmendel

from pandas/tests/groupby/aggregate/test_other.py test_agg_timezone_round_trip:

dates = [pd.Timestamp("2016-01-0%d 12:00:00" % i, tz='US/Pacific')
                 for i in range(1, 5)]
df = pd.DataFrame({'A': ['a', 'b'] * 2, 'B': dates})
grouped = df.groupby('A')
    
ts = df['B'].iloc[0]
assert ts == grouped.nth(0)['B'].iloc[0]
assert ts == grouped.head(1)['B'].iloc[0]
assert ts == grouped.first()['B'].iloc[0]
assert ts == grouped.apply(lambda x: x.iloc[0])[0]

The last assertion here is failing in a WIP branch, so I'm troubleshooting it on master and finding that it fails if I skip the first three assertions:

dates = [pd.Timestamp("2016-01-0%d 12:00:00" % i, tz='US/Pacific')
                 for i in range(1, 5)]
df = pd.DataFrame({'A': ['a', 'b'] * 2, 'B': dates})
grouped = df.groupby('A')
assert ts == grouped.apply(lambda x: x.iloc[0])[0]  # <-- KeyError: 0

Current thought is that the assertion is wrong and the test along with it. Thoughts @jreback @jorisvandenbossche ? (I don't do much in this part of the code; anyone else I should be pinging for it?)

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugGroupbyTestingpandas testing functions or related to the test suite

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions