-
-
Notifications
You must be signed in to change notification settings - Fork 105
refactor(Taxonomy): replace TAXONOMY_URLS with TAXONOMY_MAPPING and a single method to build the url #475
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
refactor(Taxonomy): replace TAXONOMY_URLS with TAXONOMY_MAPPING and a single method to build the url #475
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -891,28 +891,47 @@ class DatasetType(str, enum.Enum): | |
|
|
||
|
|
||
| class TaxonomyType(str, enum.Enum): | ||
| category = "category" | ||
| ingredient = "ingredient" | ||
| label = "label" | ||
| brand = "brand" | ||
| packaging_shape = "packaging_shape" | ||
| packaging_material = "packaging_material" | ||
| packaging_recycling = "packaging_recycling" | ||
| country = "country" | ||
| store = "store" | ||
| nova_group = "nova_group" | ||
| packaging = "packaging" | ||
| additive = "additive" | ||
| vitamin = "vitamin" | ||
| mineral = "mineral" | ||
| amino_acid = "amino_acid" | ||
| nucleotide = "nucleotide" | ||
| allergen = "allergen" | ||
| state = "state" | ||
| data_quality = "data_quality" | ||
| origin = "origin" | ||
| language = "language" | ||
| other_nutritional_substance = "other_nutritional_substance" | ||
| dataset_filename: str | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @raphodn I'm really not a fan of storing additional data in an Enum.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aaah i shouldn't have merged. Can i force push and drop the commit on the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It'd be better if every filename mapped perfectly to the enum, there's at least 1 plural exception 😅
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok did a PR instead: #479 |
||
|
|
||
| category = ("category", "categories.full.json") | ||
| ingredient = ("ingredient", "ingredients.full.json") | ||
| label = ("label", "labels.full.json") | ||
| brand = ("brand", "brands.full.json") | ||
| packaging_shape = ("packaging_shape", "packaging_shapes.full.json") | ||
| packaging_material = ("packaging_material", "packaging_materials.full.json") | ||
| packaging_recycling = ("packaging_recycling", "packaging_recycling.full.json") | ||
| country = ("country", "countries.full.json") | ||
| store = ("store", "stores.full.json") | ||
| nova_group = ("nova_group", "nova_groups.full.json") | ||
| packaging = ("packaging", "packaging.full.json") | ||
| additive = ("additive", "additives.full.json") | ||
| vitamin = ("vitamin", "vitamins.full.json") | ||
| mineral = ("mineral", "minerals.full.json") | ||
| amino_acid = ("amino_acid", "amino_acids.full.json") | ||
| nucleotide = ("nucleotide", "nucleotides.full.json") | ||
| allergen = ("allergen", "allergens.full.json") | ||
| state = ("state", "states.full.json") | ||
| data_quality = ("data_quality", "data_quality.full.json") | ||
| origin = ("origin", "origins.full.json") | ||
| language = ("language", "languages.full.json") | ||
| other_nutritional_substance = ( | ||
| "other_nutritional_substance", | ||
| "other_nutritional_substances.full.json", | ||
| ) | ||
|
|
||
| def __new__(cls, value: str, dataset_filename: str): | ||
| """ | ||
| Override __new__ to allow storing the dataset filename | ||
| associated with each taxonomy type. | ||
| """ | ||
| obj = str.__new__(cls, value) | ||
| obj._value_ = value | ||
| obj.dataset_filename = dataset_filename | ||
| return obj | ||
|
|
||
| @property | ||
| def dataset_path(self) -> str: | ||
| return f"data/taxonomies/{self.dataset_filename}" | ||
|
|
||
|
|
||
| class NutritionV3NutrientAggregated(BaseModel): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added to avoid
mypyerror