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

Groupby.groups doesn't work by a groups convert from DateTimeIndex #11442

Closed
grgsolymosi opened this issue Oct 27, 2015 · 6 comments · Fixed by #14952
Closed

Groupby.groups doesn't work by a groups convert from DateTimeIndex #11442

grgsolymosi opened this issue Oct 27, 2015 · 6 comments · Fixed by #14952
Milestone

Comments

@grgsolymosi
Copy link

i = pd.DatetimeIndex(pd.date_range('2015/01/01', periods=5), name='date')
d = pd.DataFrame({'A':[5,6,7,8,9], 'B':[1,2,3,4,5]}, index=i)

print i
print d

dg = d.groupby(level='date')

print dg.get_group('2015-01-01')
print dg.groups

Output:

DatetimeIndex(['2015-01-01', '2015-01-02', '2015-01-03', '2015-01-04',
               '2015-01-05'],
              dtype='datetime64[ns]', name=u'date', freq='D', tz=None)
            A  B
date            
2015-01-01  5  1
2015-01-02  6  2
2015-01-03  7  3
2015-01-04  8  4
2015-01-05  9  5
            A  B
date            
2015-01-01  5  1
Traceback (most recent call last):

  File "<ipython-input-2-f2b4d1146750>", line 12, in <module>
    print dg.groups

  File "/home/george/anaconda/lib/python2.7/site-packages/pandas/core/groupby.py", line 405, in groups
    return self.grouper.groups

  File "pandas/src/properties.pyx", line 34, in pandas.lib.cache_readonly.__get__ (pandas/lib.c:41917)

  File "/home/george/anaconda/lib/python2.7/site-packages/pandas/core/groupby.py", line 1352, in groups
    return self.groupings[0].groups

  File "pandas/src/properties.pyx", line 34, in pandas.lib.cache_readonly.__get__ (pandas/lib.c:41917)

  File "/home/george/anaconda/lib/python2.7/site-packages/pandas/core/groupby.py", line 2041, in groups
    return self.index.groupby(self.grouper)

  File "/home/george/anaconda/lib/python2.7/site-packages/pandas/tseries/base.py", line 60, in groupby
    return _algos.groupby_object(objs, f)

TypeError: Argument 'labels' has incorrect type (expected numpy.ndarray, got DatetimeIndex)
@jreback
Copy link
Contributor

jreback commented Oct 27, 2015

hmm, does seem a bit buggy

@jreback
Copy link
Contributor

jreback commented Dec 24, 2015

@temmplar reason you closed this?

@jreback jreback reopened this Dec 24, 2015
@grgsolymosi
Copy link
Author

@jreback sorry I guess, I'm not familiar with the system and I thought if you answered I have to close it.

@jreback
Copy link
Contributor

jreback commented Dec 24, 2015

nope
would be closed by a pull request to fix which are welcome!

@jzwinck
Copy link
Contributor

jzwinck commented Aug 5, 2016

I tried this in tseries/base.py:

-        return _algos.groupby_object(objs, f)
+        return _algos.groupby_object(objs, np.asarray(f))

And it sort of works, but the results are ugly, especially if a timezone is involved. An index like this:

DatetimeIndex(['2016-06-28 05:30:00-05:00', '2016-06-28 05:31:00-05:00'], dtype='datetime64[ns, America/Chicago]')

Produces naive UTC results:

{numpy.datetime64('2016-06-28T10:30:00.000000000'): [Timestamp('2016-06-28 05:30:00-0500', ...

@jreback Do you have any idea how to fix this simply and properly?

@akapocsi
Copy link

I am getting this error too.

mroeschke added a commit to mroeschke/pandas that referenced this issue Dec 22, 2016
@jreback jreback modified the milestones: 0.20.0, Next Major Release Dec 22, 2016
mroeschke added a commit to mroeschke/pandas that referenced this issue Dec 23, 2016
jreback pushed a commit that referenced this issue Dec 23, 2016
ShaharBental pushed a commit to ShaharBental/pandas that referenced this issue Dec 26, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants