Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: first() loses the timezone in groupby #15884

Closed
chrisaycock opened this issue Apr 3, 2017 · 2 comments · Fixed by #21573
Closed

BUG: first() loses the timezone in groupby #15884

chrisaycock opened this issue Apr 3, 2017 · 2 comments · Fixed by #21573
Labels
Bug Groupby Timezones Timezone data dtype
Milestone

Comments

@chrisaycock
Copy link
Contributor

chrisaycock commented Apr 3, 2017

need a systematic test of all groupby methods here.

This works as expected:

pd.DataFrame({'time': [pd.Timestamp('2012-01-01 13:00:00+00:00')],
              'A': [3]}).groupby('A', as_index=False).head(1)

However, this loses the timezone:

pd.DataFrame({'time': [pd.Timestamp('2012-01-01 13:00:00+00:00')],
              'A': [3]}).groupby('A', as_index=False).first()
@chrisaycock chrisaycock changed the title first() loses the timezone BUG: first() loses the timezone Apr 3, 2017
@jreback
Copy link
Contributor

jreback commented Apr 3, 2017

so this falls down: https://github.com/pandas-dev/pandas/blob/master/pandas/core/groupby.py#L1929

essentially .values is a DatetimeIndex at this point, not a numpy array. (because its passed block.values higher up). So this needs to be handled.

@jreback jreback added Groupby Timezones Timezone data dtype Bug labels Apr 3, 2017
@jreback jreback added this to the Next Minor Release milestone Apr 3, 2017
@jreback jreback modified the milestones: Interesting Issues, Next Major Release Nov 26, 2017
@jreback jreback added this to Dtypes in Interesting Things Nov 26, 2017
@jreback jreback changed the title BUG: first() loses the timezone BUG: first() loses the timezone in groupby Mar 7, 2018
@mroeschke
Copy link
Member

I believe the solution to this issue xrefs to #19026 (here), where np.asarray will convert the datetimetz dtype to just a datetime dtype.

@jreback jreback modified the milestones: Next Major Release, 0.24.0 Jun 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Groupby Timezones Timezone data dtype
Projects
No open projects
3 participants