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

Error with dataframes containing non-string column names #108

Closed
MarinManuel opened this issue Nov 28, 2020 · 4 comments
Closed

Error with dataframes containing non-string column names #108

MarinManuel opened this issue Nov 28, 2020 · 4 comments

Comments

@MarinManuel
Copy link
Contributor

I've noticed DABEST does not let me work with dataframes where column names are not strings.

example:

import dabest
import pandas as pd
import numpy as np
from itertools import combinations
from pprint import pprint

print(dabest.__version__)

columns = [1, 2.0]
# create a test database
N = 100
df = pd.DataFrame(np.vstack([np.random.normal(loc=i, size=(N,)) for i in range(len(columns))]).T, columns=columns)

db = dabest.load(data=df, idx=columns)
print(db.mean_diff)

results in an Exception:

0.3.0
Traceback (most recent call last):
 File "<ipython-input-10-19e1ff62e09f>", line 14, in <module>
   db = dabest.load(data=df, idx=columns)
 File "/.../anaconda3/lib/python3.7/site-packages/dabest/_api.py", line 65, in load
  return Dabest(data, idx, x, y, paired, id_col, ci, resamples, random_seed)
 File "/.../anaconda3/lib/python3.7/site-packages/dabest/_classes.py", line 67, in __init__
   raise ValueError(err)
ValueError: There seems to be a problem with the idx you

As far as I understand, any hashable can be used as a column name (an Index really). I'm not sure what use case there is for exotic types, but I often have columns that are named with int or float.

I'm going to propose a fix, but I'm not entirely sure the solution is robust. I'm would test for Hashable instead of str, but some iterables are hashables (frozensets, tuples, range) and I don't quite know how you'd deal with that.

PLUS there is an independent but related bug in pandas that prevents the fix from working. See here. The bug was fixed in v.1.0.0 and DABEST would need to require that version to work properly.

@MarinManuel
Copy link
Contributor Author

disregard the part about change the req for pandas. I don't know why my pandas version was stuck at 0.25.x in my test environment. I just realized that DABEST requires pandas v.1.1 now.

@MarinManuel
Copy link
Contributor Author

Further tests showed that my initial fix was not working. I suggest testing for str, int and float idx. I'm sure there might be cases where that's not enough, but that probably covers most use cases?

Jacobluke- added a commit that referenced this issue Feb 22, 2024
Solves issue #108  by converting all non-string color_groups to strings
Jacobluke- added a commit that referenced this issue Feb 22, 2024
Solves issue #108  by converting all non-string color_groups to strings
Jacobluke- added a commit that referenced this issue Feb 22, 2024
Solves issue #108  by converting all non-string color_groups to strings
Jacobluke- added a commit that referenced this issue Feb 27, 2024
Fix the bug #108 where non-string column names are supplied in DABEST usages by coordinating with the deprecation of providing only ‘palette’ with no ‘hue’
@Jacobluke-
Copy link
Collaborator

The bug is solved.

@Jacobluke- Jacobluke- reopened this Mar 25, 2024
Jacobluke- added a commit that referenced this issue Mar 25, 2024
Fix the bug for issue #108
@Jacobluke-
Copy link
Collaborator

Solved in PR #174.

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

No branches or pull requests

2 participants