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: Using kwargs in Rolling.apply() #33433

Closed
2 of 3 tasks
echasnovski opened this issue Apr 9, 2020 · 1 comment · Fixed by #33983
Closed
2 of 3 tasks

BUG: Using kwargs in Rolling.apply() #33433

echasnovski opened this issue Apr 9, 2020 · 1 comment · Fixed by #33983
Labels
Bug Regression Functionality that used to work in a prior pandas version Window rolling, ewma, expanding
Milestone

Comments

@echasnovski
Copy link

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Code Sample, a copy-pastable example

from functools import partial

import numpy as np
import pandas as pd


def foo(x, par):
    return np.sum(x + par)


df = pd.DataFrame({"gr": [1, 1], "a": [1, 2]})

# With `kwargs`
try:
    print(df.groupby("gr")["a"].rolling(1).apply(foo, kwargs={"par": 10}))
except Exception as e:
    print(e)

# Using `partial`
bar = partial(foo, par=10)
print(df.groupby("gr")["a"].rolling(1).apply(bar))

Problem description

Expected: using appropriate kwargs argument for pandas.core.window.rolling.Rolling.apply() should be equivalent to premodifying supplied function with functools.partial() (because it is stated in documentation).
Current: kwargs doesn't seem to be used at all, because it results into "missing 1 required positional argument" exception.
Note: This works as expected in pandas 0.25.3, but gives error as early as 1.0.0.

Expected Output

gr   
1   0    11.0
    1    12.0
Name: a, dtype: float64
gr   
1   0    11.0
    1    12.0
Name: a, dtype: float64

Output of pd.show_versions()

INSTALLED VERSIONS

commit : None
python : 3.8.2.final.0
python-bits : 64
OS : Linux
OS-release : 4.15.0-29-generic
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : ru_UA.UTF-8
LOCALE : ru_UA.UTF-8

pandas : 1.0.3
numpy : 1.18.1
pytz : 2019.3
dateutil : 2.8.1
pip : 20.0.2
setuptools : 46.1.3.post20200325
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pytest : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None
numba : None

@echasnovski echasnovski added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 9, 2020
@jreback jreback added this to the 1.1 milestone May 5, 2020
@jreback jreback added Window rolling, ewma, expanding and removed Needs Triage Issue that has not been reviewed by a pandas team member labels May 5, 2020
@simonjayhawkins
Copy link
Member

Note: This works as expected in pandas 0.25.3, but gives error as early as 1.0.0.

regression in #29428 (i.e. 1.0.0)

6e5d148 is the first bad commit
commit 6e5d148
Author: Matthew Roeschke [email protected]
Date: Thu Nov 21 04:59:30 2019 -0800

REF: Separate window bounds calculation from aggregation functions (#29428)

@simonjayhawkins simonjayhawkins added the Regression Functionality that used to work in a prior pandas version label May 8, 2020
@simonjayhawkins simonjayhawkins modified the milestones: 1.1, 1.0.4 May 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Regression Functionality that used to work in a prior pandas version Window rolling, ewma, expanding
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants