Skip to content

Iterating over groupby fails with period-indexed dataframe #3579

Closed
@goyodiaz

Description

@goyodiaz

I have found this while working with period-indexed data frames on Windows XP 32 bits:

import numpy as np
import pandas as pd
index = pd.period_range(start='1999-01', periods=5, freq='M')
s1 = pd.Series(np.random.rand(len(index)), index=index)
s2 = pd.Series(np.random.rand(len(index)), index=index)
series = [('s1', s1), ('s2',s2)]
df = pd.DataFrame.from_items(series)
grouped = df.groupby(df.index.month)
list(grouped)

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\Python27\lib\site-packages\pandas\core\groupby.py", line 595, in get_iterator
    for key, (i, group) in izip(keys, splitter):
  File "D:\Python27\lib\site-packages\pandas\core\groupby.py", line 2214, in __iter__
    sdata = self._get_sorted_data()
  File "D:\Python27\lib\site-packages\pandas\core\groupby.py", line 2231, in _get_sorted_data
    return self.data.take(self.sort_idx, axis=self.axis)
  File "D:\Python27\lib\site-packages\pandas\core\frame.py", line 2891, in take
    new_index = self.index.take(indices)
  File "D:\Python27\lib\site-packages\pandas\tseries\period.py", line 1110, in take
    taken = self.values.take(indices, axis=axis)
TypeError: Cannot cast array data from dtype('int64') to dtype('int32') according to the rule 'safe'

This happens with the last stable version 0.11.0. However iterating over grouped.s1 or grouped.s2 just works.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions