Skip to content

rolling agg raise error #27601

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
ytcpub opened this issue Jul 25, 2019 · 1 comment
Closed

rolling agg raise error #27601

ytcpub opened this issue Jul 25, 2019 · 1 comment
Labels
Duplicate Report Duplicate issue or pull request

Comments

@ytcpub
Copy link

ytcpub commented Jul 25, 2019

Code Sample, a copy-pastable example if possible

df = pd.DataFrame(
{'code':['1', '1', '1', '3'], 'desc':['hello', 'my name is', 'rock', 'bye']},
index=pd.date_range('2018-01-01', periods=4, freq='1s')
)
df.groupby(['code']).rolling('2s').agg({'desc': 'count'})

df.groupby(['code']).rolling('2s').agg({'desc': ' '.join})
df.groupby(['code']).agg({'desc': ' '.join})

#### Problem description
i want a function like rolling with time and group concat string rows
but when use rolling('2s').agg({'desc': ' '.join}) , it raise error, I reference https://github.com/pandas-dev/pandas/issues/20773, but that code not work, not the value but direct raise exception: TypeError: cannot handle this type -> object

error log tail:
d:\program\python37\lib\site-packages\pandas\core\window.py in apply(self, func, raw, args, kwargs)
   1701     def apply(self, func, raw=None, args=(), kwargs={}):
   1702         return super(Rolling, self).apply(
-> 1703             func, raw=raw, args=args, kwargs=kwargs)
   1704
   1705     @Substitution(name='rolling')

d:\program\python37\lib\site-packages\pandas\core\window.py in apply(self, func, raw, args, kwargs)
   1010
   1011         return self._apply(f, func, args=args, kwargs=kwargs,
-> 1012                            center=False, raw=raw)
   1013
   1014     def sum(self, *args, **kwargs):

d:\program\python37\lib\site-packages\pandas\core\window.py in _apply(self, func, name, window, center, check_minp, **kwargs)
    839         results = []
    840         for b in blocks:
--> 841             values = self._prep_values(b.values)
    842
    843             if values.size == 0:

d:\program\python37\lib\site-packages\pandas\core\window.py in _prep_values(self, values, kill_inf)
    212             except (ValueError, TypeError):
    213                 raise TypeError("cannot handle this type -> {0}"
--> 214                                 "".format(values.dtype))
    215
    216         if kill_inf:

TypeError: cannot handle this type -> object

#### Expected Output
                    code        desc
2018-01-01 00:00:00    1       hello
2018-01-01 00:00:01    1  hello my name is 
2018-01-01 00:00:02    1       my name is  rock
2018-01-01 00:00:03    3         bye

#### Output of ``pd.show_versions()``

INSTALLED VERSIONS
------------------
commit: None
python: 3.7.2.final.0
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 158 Stepping 12, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None

pandas: 0.24.2
pytest: None
pip: 19.0.3
setuptools: 40.6.2
Cython: None
numpy: 1.16.2
scipy: 1.2.1
pyarrow: None
xarray: None
IPython: 7.3.0
sphinx: None
patsy: None
dateutil: 2.8.0
pytz: 2018.9
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 3.0.3
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml.etree: 4.3.2
bs4: 4.7.1
html5lib: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.10.1
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
gcsfs: None
@mroeschke
Copy link
Member

As you mention, this is a duplicate of #20773.

Always open to PRs for this feature. For interim solutions, please consult Stack Overflow.

@mroeschke mroeschke added the Duplicate Report Duplicate issue or pull request label Jul 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate Report Duplicate issue or pull request
Projects
None yet
Development

No branches or pull requests

2 participants