Skip to content

SeriesGroupby transform unique not working in Pandas 1.0.1 #31849

Closed
@Shawe82

Description

@Shawe82

Code Sample, a copy-pastable example if possible

# Your code here
import pandas as pd
df = pd.DataFrame({"title":['a','b','c','c','a'], "asset_id":['a1','b1','c1','c2','c1']})
df.groupby("title").asset_id.transform("unique")

Problem description

Since pandas 1.0.1, unique does not seem to be a whitelisted transform function for SeriesGroupby objects anymore. The above code works with pandas 0.25.3 but not with 1.0.1 It raises a ValueError exception:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-1-ccb0ce21c35f> in <module>
      1 import pandas as pd
      2 df = pd.DataFrame({"title":['a','b','c','c','a'], "asset_id":['a1','b1','c1','c2','c1']})
----> 3 df.groupby("title").asset_id.transform("unique")

~/sandbox/pandas/pandas/core/groupby/generic.py in transform(self, func, *args, **kwargs)
    470         elif func not in base.transform_kernel_whitelist:
    471             msg = f"'{func}' is not a valid function name for transform(name)"
--> 472             raise ValueError(msg)
    473         elif func in base.cythonized_kernels:
    474             # cythonized transform or canned "agg+broadcast"

ValueError: 'unique' is not a valid function name for transform(name)

I tried to find a documentation on that changed but was not succesful. If that is the intended behaviour, I think it would be helpful to document it.

Expected Output

0 [a1, c1]
1 [b1]
2 [c1, c2]
3 [c1, c2]
4 [a1, c1]
Name: asset_id, dtype: object

Output of pd.show_versions()

[paste the output of pd.show_versions() here below this line]
INSTALLED VERSIONS

commit : None
python : 3.8.1.final.0
python-bits : 64
OS : Darwin
OS-release : 18.7.0
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.UTF-8
pandas : 1.0.1
numpy : 1.18.1
pytz : 2019.3
dateutil : 2.8.1
pip : 19.0.3
setuptools : 40.8.0
Cython : None
pytest : 5.3.5
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 : 5.3.5
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : 1.3.13
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None
numba : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    RegressionFunctionality that used to work in a prior pandas version

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions