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

Confusing error during metadata validation #1417

Closed
npatki opened this issue May 10, 2023 · 0 comments · Fixed by #1427
Closed

Confusing error during metadata validation #1417

npatki opened this issue May 10, 2023 · 0 comments · Fixed by #1427
Assignees
Labels
bug Something isn't working
Milestone

Comments

@npatki
Copy link
Contributor

npatki commented May 10, 2023

Environment Details

  • SDV version: 1.0.1 (latest)
  • Python version: Any
  • Operating System: Any

Error Description

I expect that metadata validation should give me readable errors. Instead I get a TypeError if I accidentally input an sdtype that is not a string.

Steps to reproduce

from sdv.metadata.single_table import SingleTableMetadata

metadata = {
    "columns": {"a": {"sdtype": None}, "b": {"sdtype": "datetime"}},
    "METADATA_SPEC_VERSION": "SINGLE_TABLE_V1"
}

metadata = SingleTableMetadata.load_from_dict(metadata)
metadata.validate()

Expected Behavior: I expect a descriptive error message, similar to what happens for all other invalid sdtypes.

InvalidMetadataError: The following errors were found in the metadata:

Invalid sdtype : 'None' is not recognized. Please use one of the supported SDV sdtypes.

Observed Behavior:

TypeError: getattr(): attribute name must be string

Stack Trace

Currently observed stack trace.

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
[<ipython-input-6-f10112f21d52>](https://localhost:8080/#) in <cell line: 1>()
----> 1 metadata.validate()

4 frames
[/usr/local/lib/python3.10/dist-packages/sdv/metadata/single_table.py](https://localhost:8080/#) in validate(self)
    462         # Validate columns
    463         for column, kwargs in self.columns.items():
--> 464             self._append_error(errors, self._validate_column, column, **kwargs)
    465 
    466         if errors:

[/usr/local/lib/python3.10/dist-packages/sdv/metadata/single_table.py](https://localhost:8080/#) in _append_error(self, errors, method, *args, **kwargs)
    440         """Inplace, append the produced error to the passed ``errors`` list."""
    441         try:
--> 442             method(*args, **kwargs)
    443         except InvalidMetadataError as e:
    444             errors.append(e)

[/usr/local/lib/python3.10/dist-packages/sdv/metadata/single_table.py](https://localhost:8080/#) in _validate_column(self, column_name, sdtype, **kwargs)
    144 
    145     def _validate_column(self, column_name, sdtype, **kwargs):
--> 146         self._validate_sdtype(sdtype)
    147         self._validate_unexpected_kwargs(column_name, sdtype, **kwargs)
    148         if sdtype == 'categorical':

[/usr/local/lib/python3.10/dist-packages/sdv/metadata/single_table.py](https://localhost:8080/#) in _validate_sdtype(self, sdtype)
    137         is_default_sdtype = sdtype in self._SDTYPE_KWARGS
    138         is_anonymized_type = sdtype in SDTYPE_ANONYMIZERS
--> 139         if not (is_default_sdtype or is_anonymized_type or is_faker_function(sdtype)):
    140             raise InvalidMetadataError(
    141                 f"Invalid sdtype : '{sdtype}' is not recognized. Please use one of the "

[/usr/local/lib/python3.10/dist-packages/sdv/metadata/anonymization.py](https://localhost:8080/#) in is_faker_function(function_name)
     57     """
     58     try:
---> 59         getattr(Faker(), function_name)
     60     except AttributeError:
     61         return False

TypeError: getattr(): attribute name must be string
@npatki npatki added the bug Something isn't working label May 10, 2023
@amontanez24 amontanez24 added this to the 1.2.0 milestone Jun 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants