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

Unexpected TypeError in remove_duplicate_columns #292

Open
NicolasGensollen opened this issue Aug 31, 2022 · 0 comments · May be fixed by #293
Open

Unexpected TypeError in remove_duplicate_columns #292

NicolasGensollen opened this issue Aug 31, 2022 · 0 comments · May be fixed by #293

Comments

@NicolasGensollen
Copy link

  • What is the current behavior?

When summing FixedEffect instances built from a Pandas DataFrame with converted dtypes, the function remove_duplicate_columns in brainstat/stats/terms.py raises the following error:

File ~/GitRepos/BrainStat/brainstat/stats/terms.py:243, in remove_duplicate_columns(df, tol)
    241 df *= 1 / tol
    242 # keep = df.round().T.drop_duplicates(keep="last").T.columns  # Slow!!
--> 243 idx = np.unique(df.round().values, axis=1, return_index=True)[-1]
    244 keep = df.columns[sorted(idx)]
    245 return keep

TypeError: The axis argument to unique is not supported for dtype object
  • Please provide the steps to reproduce and if possible a minimal demo of the problem.

Here is a MWE:

import pandas as pd
from brainstat.stats.terms import FixedEffect

df = pd.DataFrame({"age": [20.2, 33.1, 25.0],
                   "sex": ["Female", "Male", "Male"],
                  }).convert_dtypes()
df = df.apply(lambda x: x.astype('category') if x.name == "sex" else x)
FixedEffect(df.age) + FixedEffect(df.sex)
  • What is the expected behavior?

No crash.

  • Please tell us about your computing environment:

Python 3.9.11
Brainstat 0.3.6

  • Other information
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant