Skip to content

TypeError: copy() takes no keyword arguments #31441

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
BayerSe opened this issue Jan 30, 2020 · 8 comments · Fixed by #31456
Closed

TypeError: copy() takes no keyword arguments #31441

BayerSe opened this issue Jan 30, 2020 · 8 comments · Fixed by #31456
Assignees
Labels
Groupby Regression Functionality that used to work in a prior pandas version
Milestone

Comments

@BayerSe
Copy link

BayerSe commented Jan 30, 2020

Code Sample, a copy-pastable example if possible

import pandas as pd

df = pd.DataFrame(['A', 'A', 'B', 'B'], columns=['grps'])
df.groupby('grps').apply(lambda x: x.index.to_list())
Traceback (most recent call last):
  File "/home/bay2rng/miniconda3/envs/p356_rtp_production_scheduling/lib/python3.7/site-packages/pandas/core/groupby/groupby.py", line 735, in apply
    result = self._python_apply_general(f)
  File "/home/bay2rng/miniconda3/envs/p356_rtp_production_scheduling/lib/python3.7/site-packages/pandas/core/groupby/groupby.py", line 751, in _python_apply_general
    keys, values, mutated = self.grouper.apply(f, self._selected_obj, self.axis)
  File "/home/bay2rng/miniconda3/envs/p356_rtp_production_scheduling/lib/python3.7/site-packages/pandas/core/groupby/ops.py", line 171, in apply
    result_values, mutated = splitter.fast_apply(f, group_keys)
  File "/home/bay2rng/miniconda3/envs/p356_rtp_production_scheduling/lib/python3.7/site-packages/pandas/core/groupby/ops.py", line 925, in fast_apply
    return libreduction.apply_frame_axis0(sdata, f, names, starts, ends)
  File "pandas/_libs/reduction.pyx", line 505, in pandas._libs.reduction.apply_frame_axis0
TypeError: copy() takes no keyword arguments
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/home/bay2rng/miniconda3/envs/p356_rtp_production_scheduling/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3319, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-2-a3e576516eed>", line 4, in <module>
    df.groupby('grps').apply(lambda x: x.index.to_list())
  File "/home/bay2rng/miniconda3/envs/p356_rtp_production_scheduling/lib/python3.7/site-packages/pandas/core/groupby/groupby.py", line 746, in apply
    return self._python_apply_general(f)
  File "/home/bay2rng/miniconda3/envs/p356_rtp_production_scheduling/lib/python3.7/site-packages/pandas/core/groupby/groupby.py", line 751, in _python_apply_general
    keys, values, mutated = self.grouper.apply(f, self._selected_obj, self.axis)
  File "/home/bay2rng/miniconda3/envs/p356_rtp_production_scheduling/lib/python3.7/site-packages/pandas/core/groupby/ops.py", line 171, in apply
    result_values, mutated = splitter.fast_apply(f, group_keys)
  File "/home/bay2rng/miniconda3/envs/p356_rtp_production_scheduling/lib/python3.7/site-packages/pandas/core/groupby/ops.py", line 925, in fast_apply
    return libreduction.apply_frame_axis0(sdata, f, names, starts, ends)
  File "pandas/_libs/reduction.pyx", line 505, in pandas._libs.reduction.apply_frame_axis0
TypeError: copy() takes no keyword arguments

Problem description

This snippet is working well on version 0.25.3. It breaks in version 1.0.0.

Expected Output

A    [0, 1]
B    [2, 3]
dtype: object

Output of pd.show_versions()

INSTALLED VERSIONS

commit : None
python : 3.7.6.final.0
python-bits : 64
OS : Linux
OS-release : 4.15.0-72-generic
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.0.0
numpy : 1.18.1
pytz : 2019.3
dateutil : 2.8.1
pip : 20.0.2
setuptools : 45.1.0.post20200127
Cython : None
pytest : 5.3.2
hypothesis : None
sphinx : 2.3.1
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.10.3
IPython : 7.11.1
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : 3.1.2
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 0.15.1
pytables : None
pytest : 5.3.2
pyxlsb : None
s3fs : None
scipy : 1.4.1
sqlalchemy : 1.3.13
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None
numba : None

@jorisvandenbossche jorisvandenbossche added the Regression Functionality that used to work in a prior pandas version label Jan 30, 2020
@jorisvandenbossche jorisvandenbossche added this to the 1.0.1 milestone Jan 30, 2020
@jorisvandenbossche
Copy link
Member

@BayerSe thanks for the report!

cc @jbrockmendel

@getsanjeevdubey
Copy link

@BayerSe @jorisvandenbossche I get the same error in 0.25.3
Not on this above mentioned dataframe, but on my own data.

@MarcoGorelli
Copy link
Member

MarcoGorelli commented Jan 30, 2020

When the code reaches "pandas/_libs/reduction.pyx", line 505:

                    piece = piece.copy(deep="all")

then piece is

<class 'list'>
[0, 1]

Is the fix here to use copy.deepcopy if piece is a list?

@jbrockmendel
Copy link
Member

I think this is caused by #28662, cc @dsaxton.

@getsanjeevdubey
Copy link

@jbrockmendel Any immediate solutions, is it fixed in other versions like 0.25.1

@dsaxton
Copy link
Member

dsaxton commented Jan 31, 2020

I think this is caused by #28662, cc @dsaxton.

@jbrockmendel I think you're right. The implicit assumption there was apparently that piece would be a pandas object, but as the list example shows that doesn't have to be true.

@jreback
Copy link
Contributor

jreback commented Feb 1, 2020

use a try/except around the .copy(..)

will fix this (and use deepcopy in the except

@MarcoGorelli
Copy link
Member

MarcoGorelli commented Feb 1, 2020

and use deepcopy in the except

Tried that, but then pandas/tests/plotting/test_groupby.py::TestDataFrameGroupByPlots.test_plot_kwargs fails.

Also, I wasn't able to reproduce an example where using copy (instead of deepcopy) doesn't give the output I was expecting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Groupby Regression Functionality that used to work in a prior pandas version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants