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

aggtarget with small dataframe #1018

Open
jeromedockes opened this issue Jul 29, 2024 · 0 comments
Open

aggtarget with small dataframe #1018

jeromedockes opened this issue Jul 29, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@jeromedockes
Copy link
Member

jeromedockes commented Jul 29, 2024

Describe the bug

while investing #1005 I got an unrelated error with aggtarget. I think it only happens for super small dataframes so probably not important but I'm opening an issue to keep track of it in case it pops up again anyway

Steps/Code to Reproduce

import numpy as np
import pandas as pd
from skrub import AggTarget

X = pd.DataFrame(dict(a=[1, 2, 1]))
y = np.array([100., -10.0,200.0 ])

AggTarget(main_key="a", operation=["hist(2)"]).fit_transform(X, y)

Expected Results

no error

Actual Results

Traceback (most recent call last):
  File "/home/jerome/workspace/scratch/2024/07/scratch.py", line 8, in <module>
    AggTarget(main_key="a", operation=["hist(2)"]).fit_transform(X, y)
  File "/home/jerome/.virtualenvs/skrub/lib/python3.10/site-packages/sklearn/utils/_set_output.py", line 313, in wrapped
    data_to_wrap = f(self, X, *args, **kwargs)
  File "/home/jerome/.virtualenvs/skrub/lib/python3.10/site-packages/sklearn/base.py", line 1101, in fit_transform
    return self.fit(X, y, **fit_params).transform(X)
  File "/home/jerome/workspace/backedup_repositories/skrub/skrub/_agg_joiner.py", line 480, in fit
    self.y_ = skrub_px.aggregate(
  File "/home/jerome/workspace/backedup_repositories/skrub/skrub/_dataframe/_pandas.py", line 136, in aggregate
    serie_group = table.groupby(key)[col_to_agg].value_counts(**kwargs)
  File "/home/jerome/.virtualenvs/skrub/lib/python3.10/site-packages/pandas/core/groupby/generic.py", line 857, in value_counts
    sorter = np.lexsort((out if ascending else -out, left[0]))
ValueError: all keys need to be the same shape

Versions

I can reproduce it with skrub 1.0.0 or the main branch

pandas

I guess this is an issue in pandas?

import pandas as pd

df = pd.DataFrame(dict(y=[100, -10, 200], a=[1, 2, 1]))
df.groupby('a')['y'].value_counts(bins=[-10.,  95., 200.])
Traceback (most recent call last):
  File "/home/jerome/workspace/scratch/2024/07/value_counts.py", line 4, in <module>
    df.groupby('a')['y'].value_counts(bins=[-10.,  95., 200.])
  File "/home/jerome/.virtualenvs/skrub/lib/python3.10/site-packages/pandas/core/groupby/generic.py", line 857, in value_counts
    sorter = np.lexsort((out if ascending else -out, left[0]))
ValueError: all keys need to be the same shape

@jeromedockes jeromedockes added the bug Something isn't working label Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant