Skip to content

groupby.first() casts datetime64[ns] series to 'object' with 'long" elements #2133

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

Closed
gerigk opened this issue Oct 26, 2012 · 6 comments
Closed
Labels
Milestone

Comments

@gerigk
Copy link

gerigk commented Oct 26, 2012

import numpy as np
import pandas as pd
df = pd.DataFrame([(1, 1351036800000000000), (2, 1351036800000000000)])
df[1] = df[1].view('M8[ns]')
print df[1].dtype
print df.groupby(0).first()[1].dtype
print type(df.groupby(0).first()[1][1])

datetime64[ns]
object
<type 'long'>
@wesm
Copy link
Member

wesm commented Nov 3, 2012

There's a couple issues here. looking into it

@wesm wesm closed this as completed in adc9238 Nov 4, 2012
@wesm
Copy link
Member

wesm commented Nov 4, 2012

Dear lord don't look at what I had to do to fix this in a simple/dirty way

@gerigk
Copy link
Author

gerigk commented Nov 15, 2012

@wesm I don't know whether this reopens the issue:

I received the following error after updating pandas:

ind_part = df[time_dim].groupby(level=group_dims).first()
  File "/usr/local/lib/python2.7/dist-packages/pandas-0.9.2.dev_4519310-py2.7-linux-x86_64.egg/pandas/core/groupby.py", line 38, in f
    result = result.convert_objects()
AttributeError: 'Series' object has no attribute 'convert_objects'

I fixed it by using

DataFrame(df[time_dim]).groupby(level=group_dims).first()

which kind of lets me think that your fix only works for DataFrames but not for Series.

@wesm wesm reopened this Nov 17, 2012
@wesm
Copy link
Member

wesm commented Nov 17, 2012

I'll have a look

@changhiskhan
Copy link
Contributor

Please don't look at this one either :)

@changhiskhan
Copy link
Contributor

closed via a28a5cc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants