-
Notifications
You must be signed in to change notification settings - Fork 1
Preserve dtypes when get() is called with an index #346
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
Conversation
Codecov Report
|
|
Interestingly, this does not solve #324 completely: import audformat
db = audformat.Database('db')
db.schemes['spk'] = audformat.Scheme('str', labels=['a', 'b'])
index = audformat.filewise_index(['f1'])
db['files'] = audformat.Table(index)
db['files']['spk'] = audformat.Column(scheme_id='spk')
db['files']['spk'].set(['a'])
db.schemes['label'] = audformat.Scheme('int')
index = audformat.segmented_index(['f1', 'f1'], [0, 1], [1, 2])
db['segments'] = audformat.Table(index)
db['segments']['label'] = audformat.Column(scheme_id='label')
db['segments']['label'].set([0, 1])and then: >>> df = db['files'].get()
>>> df.spk.cat.categories
Index(['a', 'b'], dtype='object')
>>> df.loc['f1', 'spk'] = 'c'
...
TypeError: Cannot setitem on a Categorical with a new category (c), set the categories first
>>> df
spk
file
f1 abut >>> df = db['files'].get(db['segments'].index)
>>> df.spk.cat.categories
Index(['a', 'b'], dtype='object')
>>> df.loc['f1', 'spk'] = 'c'
>>> df
spk
file start end
f1 0 days 00:00:00 0 days 00:00:01 c
0 days 00:00:01 0 days 00:00:02 c
>>> df.spk.cat.categories
...
AttributeError: Can only use .cat accessor with a 'category' dtypeBut maybe the difference in behavior is now attributed to the fact that the first is a filewise index whereas the second a segmented index? |
Maybe a bug in df = db['files'].get()
df.spk.cat.categoriesdf = db['files'].get(db['segments'].index)
df.spk.cat.categoriesSo I guess there is not much we can do about it. |
|
I would then propose that we remove "Closes #324" here and update the issue after this is merged. |
|
Ok, but then we should at least remove the 'bug' label from #324 as I don't see we can do anything else but make sure the categorical dtype is kept. |
|
OK, let's leave the "Close #324" here as CategoricalDtype is now indeed preserved. I will open a new issue after this here is merged. |
Closes #324
Solves issue described in #324 and adds a test for it.