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

Add method to drop scheme from database #299

Open
frankenjoe opened this issue Aug 18, 2022 · 2 comments
Open

Add method to drop scheme from database #299

frankenjoe opened this issue Aug 18, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@frankenjoe
Copy link
Collaborator

frankenjoe commented Aug 18, 2022

To avoid that a user removes a scheme that is used in a table, it could make sense to introduce Database.drop_scheme() to raise an error in that case.

@frankenjoe frankenjoe added the enhancement New feature or request label Aug 18, 2022
@frankenjoe
Copy link
Collaborator Author

@hagenw what is your take here? Since we also don't have methods to drop media, raters, attachments etc. I wonder if we should simply close the issue as I don't see us implementing all those methods at the moment.

@hagenw
Copy link
Member

hagenw commented Jan 18, 2023

I'm not completely sure if we can argue that we also don't have drop methods for media, raters, attachments as we have audformat.Database.drop_tables() which addresses also one of the important parts of the database.

But I think it is not very urgent as you can delete a scheme with del and most of the time you do it only if really needed. And if you delete a needed scheme everything else seems to work as expected, you can even save and load the database, e.g.

import audformat


db = audformat.Database('db')

db.schemes['spk'] = audformat.Scheme('str', labels=['a', 'b'])
index = audformat.filewise_index(['f1', 'f2'])
db['files'] = audformat.Table(index)
db['files']['spk'] = audformat.Column(scheme_id='spk')
db['files']['spk'].set(['a', 'a'])

db.schemes['label'] = audformat.Scheme('int')
index = audformat.segmented_index(['f1', 'f1'], [0, 1], [1, 2])
db['segments'] = audformat.Table(index)
db['segments']['spk'] = audformat.Column(scheme_id='spk')
db['segments']['spk'].set(['a', 'a'])

and then

>>> del db.schemes['spk']
>>> db
name: db                   
source: ''                                                                          
usage: unrestricted         
languages: []                                                                       
schemes:                            
  label: {dtype: int}
tables:                                                                                  
  files:                                              
    type: filewise                                                                       
    columns:                                                                   
      spk: {scheme_id: spk}                 
  segments:                                                                    
    type: segmented
    columns:                                                                                    
      spk: {scheme_id: spk}        
>>> db.save('test-db')
>>> db = audformat.Database.load('test-db')
>>> db
name: db
source: ''
usage: unrestricted
languages: []
schemes:
  label: {dtype: int}
tables:
  files:
    type: filewise
    columns:
      spk: {scheme_id: spk}
  segments:
    type: segmented
    columns:
      spk: {scheme_id: spk}

The only not so nice think is the error message you are getting at the moment when the deleted scheme is needed:

>>> df = db['files'].get()
...
BadKeyError: "Bad key 'spk', expected one of ['label']"
>>> df = db['segments'].get()
...
BadKeyError: "Bad key 'spk', expected one of ['label']"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants