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 update_columns and update_columns_metadata methods to metadata #1804

Closed
frances-h opened this issue Feb 20, 2024 · 0 comments · Fixed by #1824
Closed

Add update_columns and update_columns_metadata methods to metadata #1804

frances-h opened this issue Feb 20, 2024 · 0 comments · Fixed by #1824
Assignees
Labels
feature request Request for a new feature
Milestone

Comments

@frances-h
Copy link
Contributor

frances-h commented Feb 20, 2024

Problem Description

As a user, it would be nice if I could update multiple columns in my metadata at once, instead of having to use update_column for every column.

metadata = SingleTableMetadata.detect_from_dataframe(data)
metadata.update_column('col1', sdtype='numerical')
metadata.update_column('col2', sdtype='numerical')
metadata.update_column('col3', sdtype='numerical')

I'd like to be able to update multiple columns that have the same metadata kwargs at once, or pass in metadata updates to multiple columns as a dictionary.

Expected behavior

Add two methods to the metadata, update_columns which updates all the given columns with the same metadata kwargs and update_columns_metadata which updates columns using metadata from the input dictionary. We should validate the inputs to verify that the columns exist and the provided arguments are valid.

Single Table API

  • update_columns(column_names, **metadata_kwargs)
    • column_names (list[str]) - a list of column names that should be updated
    • **metadata_kwargs - Any key word arguments that describe metadata for the column (i.e. sdtype, pii, computer_representation, etc.)
metadata = SingleTableMetadata.detect_from_dataframe(data)
metadata.update_columns(['col1', 'col2', 'col3'], sdtype='numerical')
  • update_columns_metadata(column_metadata_dict)
    • column_metadata_dict (dict) - a dictionary mapping column names to column metadata (i.e. {'amount': {'sdtype': 'numerical'}}
metadata = SingleTableMetadata.detect_from_dataframe(data)
metadata.update_columns_metadata({
    'col1': {'sdtype': 'numerical'},
    'col2': {'sdtype': 'address', 'pii': True},
    'col3': {'sdtype': 'id', 'regex': 'ID_[0-9]{3}'}
})

Multi Table

  • update_columns(table_name, column_names, **metadata_kwargs)
    • table_name (str) - the name of the target table
    • column_names (list[str]) - a list of column names that should be updated
    • **metadata_kwargs - Any key word arguments that describe metadata for the column (i.e. sdtype, pii, computer_representation, etc.)
metadata = .detect_from_dataframes(data)
metadata.update_columns(
 'users',
 ['col1', 'col2', 'col3'],
 sdtype='numerical'
)
  • update_columns_metadata(table_name, column_metadata_dict)
    • table_name (str) - the name of the target table
    • column_metadata_dict (dict) - a dictionary mapping column names to column metadata (i.e. {'amount': {'sdtype': 'numerical'}}
metadata = MultiTableMetadata.detect_from_dataframes(data)
metadata.update_columns_metadata(
  table_name='users',
  column_metadata_dict={
    'col1': {'sdtype': 'numerical'},
    'col2': {'sdtype': 'address', 'pii': True},
    'col3': {'sdtype': 'id', 'regex': 'ID_[0-9]{3}'}
  }
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Request for a new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants