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

Expecting column values to be of type array or list raises ValueError #1095

Closed
sam-hoffman opened this issue Feb 18, 2020 · 1 comment · Fixed by #1099
Closed

Expecting column values to be of type array or list raises ValueError #1095

sam-hoffman opened this issue Feb 18, 2020 · 1 comment · Fixed by #1099

Comments

@sam-hoffman
Copy link
Contributor

Mentioned in Slack

Adding an expectation that a column in Pandas be of type list or array raises an error:

import great_expectations as ge
import pandas as pd


df = pd.DataFrame(
    {'a':[1,2,3,4,5], 
     'b':[[1,2], [3,4], [5], [6,7,8], [9, 10, 11]]}
)
geset = ge.dataset.PandasDataset(df)

#these two work
geset.expect_column_values_to_be_of_type('a', 'int')
geset.expect_column_values_to_be_of_type('a', 'int64')


#these don't work :(
geset.expect_column_values_to_be_of_type('b', 'array')
geset.expect_column_values_to_be_of_type('b', 'list')

Traceback here:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-11-17211834476d> in <module>()
     11 
     12 #these don't work :(
---> 13 geset.expect_column_values_to_be_of_type('b', 'array')
     14 geset.expect_column_values_to_be_of_type('b', 'list')

/Users/Shared/anaconda3/lib/python3.6/site-packages/great_expectations/data_asset/util.py in f(*args, **kwargs)
     83         @wraps(self.mthd, assigned=('__name__', '__module__'))
     84         def f(*args, **kwargs):
---> 85             return self.mthd(obj, *args, **kwargs)
     86 
     87         f.__doc__ = doc

/Users/Shared/anaconda3/lib/python3.6/site-packages/great_expectations/dataset/pandas_dataset.py in expect_column_values_to_be_of_type(self, column, type_, **kwargs)
    507         else:
    508             res = self._expect_column_values_to_be_of_type__map(
--> 509                 column, type_, **kwargs
    510             )
    511             # Note: this logic is similar to the logic in _append_expectation for deciding when to overwrite an

/Users/Shared/anaconda3/lib/python3.6/site-packages/great_expectations/data_asset/data_asset.py in wrapper(self, *args, **kwargs)
    234 
    235                         else:
--> 236                             raise err
    237 
    238                 else:

/Users/Shared/anaconda3/lib/python3.6/site-packages/great_expectations/data_asset/data_asset.py in wrapper(self, *args, **kwargs)
    221                 if self._config.get("interactive_evaluation", True) or self._active_validation:
    222                     try:
--> 223                         return_obj = func(self, **evaluation_args)
    224 
    225                     except Exception as err:

/Users/Shared/anaconda3/lib/python3.6/site-packages/great_expectations/dataset/pandas_dataset.py in inner_wrapper(self, column, mostly, result_format, *args, **kwargs)
     82             else:
     83                 boolean_mapped_null_values = np.array([True if (value in ignore_values) or (pd.isnull(value)) else False
---> 84                                                        for value in series])
     85 
     86             element_count = int(len(series))

/Users/Shared/anaconda3/lib/python3.6/site-packages/great_expectations/dataset/pandas_dataset.py in <listcomp>(.0)
     82             else:
     83                 boolean_mapped_null_values = np.array([True if (value in ignore_values) or (pd.isnull(value)) else False
---> 84                                                        for value in series])
     85 
     86             element_count = int(len(series))

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
@eugmandel
Copy link
Contributor

Thank you for the fix, @sam-hoffman ! It is released in 0.9.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants