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

Object of type Decimal is not JSON serializable #6357

Closed
tooptoop4 opened this issue Nov 15, 2022 · 3 comments
Closed

Object of type Decimal is not JSON serializable #6357

tooptoop4 opened this issue Nov 15, 2022 · 3 comments
Labels
community devrel This item is being addressed by the Developer Relations Team

Comments

@tooptoop4
Copy link

>>> document_model = ProfilingResultsPageRenderer().render(validation_result)
An unexpected Exception occurred during data docs rendering.  Because of this error, certain parts of data docs will not be rendered properly and/or may not appear altogether.  Please use the trace, included in this message, to diagnose and repair the underlying issue.  Detailed information follows:
                TypeError: "Object of type Decimal is not JSON serializable".  Traceback: "Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/great_expectations/render/renderer/column_section_renderer.py", line 110, in render
    getattr(self, content_block_function_name)(evrs)
  File "/usr/local/lib/python3.10/site-packages/great_expectations/render/renderer/column_section_renderer.py", line 388, in _render_value_counts_bar_chart
    return get_renderer_impl(
  File "/usr/local/lib/python3.10/site-packages/great_expectations/render/renderer/renderer.py", line 14, in inner_func
    return renderer_fn(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/great_expectations/expectations/core/expect_column_distinct_values_to_be_in_set.py", line 334, in _descriptive_value_counts_bar_chart_renderer
    chart = bars.to_json()
  File "/usr/local/lib/python3.10/site-packages/altair/utils/schemapi.py", line 373, in to_json
    dct = self.to_dict(validate=validate, ignore=ignore, context=context)
  File "/usr/local/lib/python3.10/site-packages/altair/vegalite/v4/api.py", line 2020, in to_dict
    return super().to_dict(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/altair/vegalite/v4/api.py", line 374, in to_dict
    copy.data = _prepare_data(original_data, context)
  File "/usr/local/lib/python3.10/site-packages/altair/vegalite/v4/api.py", line 97, in _prepare_data
    data = _consolidate_data(data, context)
  File "/usr/local/lib/python3.10/site-packages/altair/vegalite/v4/api.py", line 64, in _consolidate_data
    name = _dataset_name(values)
  File "/usr/local/lib/python3.10/site-packages/altair/vegalite/v4/api.py", line 37, in _dataset_name
    values_json = json.dumps(values, sort_keys=True)
  File "/usr/local/lib/python3.10/json/__init__.py", line 238, in dumps
    **kw).encode(obj)
  File "/usr/local/lib/python3.10/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/local/lib/python3.10/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/usr/local/lib/python3.10/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type Decimal is not JSON serializable
".
An unexpected Exception occurred during data docs rendering.  Because of this error, certain parts of data docs will not be rendered properly and/or may not appear altogether.  Please use the trace, included in this message, to diagnose and repair the underlying issue.  Detailed information follows:
                TypeError: "Object of type Decimal is not JSON serializable".  Traceback: "Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/great_expectations/render/renderer/column_section_renderer.py", line 110, in render
    getattr(self, content_block_function_name)(evrs)
  File "/usr/local/lib/python3.10/site-packages/great_expectations/render/renderer/column_section_renderer.py", line 388, in _render_value_counts_bar_chart
    return get_renderer_impl(
  File "/usr/local/lib/python3.10/site-packages/great_expectations/render/renderer/renderer.py", line 14, in inner_func
    return renderer_fn(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/great_expectations/expectations/core/expect_column_distinct_values_to_be_in_set.py", line 334, in _descriptive_value_counts_bar_chart_renderer
    chart = bars.to_json()
  File "/usr/local/lib/python3.10/site-packages/altair/utils/schemapi.py", line 373, in to_json
    dct = self.to_dict(validate=validate, ignore=ignore, context=context)
  File "/usr/local/lib/python3.10/site-packages/altair/vegalite/v4/api.py", line 2020, in to_dict
    return super().to_dict(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/altair/vegalite/v4/api.py", line 374, in to_dict
    copy.data = _prepare_data(original_data, context)
  File "/usr/local/lib/python3.10/site-packages/altair/vegalite/v4/api.py", line 97, in _prepare_data
    data = _consolidate_data(data, context)
  File "/usr/local/lib/python3.10/site-packages/altair/vegalite/v4/api.py", line 64, in _consolidate_data
    name = _dataset_name(values)
  File "/usr/local/lib/python3.10/site-packages/altair/vegalite/v4/api.py", line 37, in _dataset_name
    values_json = json.dumps(values, sort_keys=True)
  File "/usr/local/lib/python3.10/json/__init__.py", line 238, in dumps
    **kw).encode(obj)
  File "/usr/local/lib/python3.10/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/local/lib/python3.10/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/usr/local/lib/python3.10/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type Decimal is not JSON serializable
".

@austiezr
Copy link
Contributor

austiezr commented Dec 1, 2022

Hey @tooptoop4 ! Are you able to provide any further context here? Workflow generating this error, your relevant configs? We're unable to investigate potential errors here without understanding how this behavior you're experiencing arose.

@austiezr austiezr added community devrel This item is being addressed by the Developer Relations Team labels Dec 1, 2022
@lu-lz
Copy link
Contributor

lu-lz commented Jan 12, 2023

Hi @austiezr ! I had the same error.

Background:
we want to do row-level validation so we configured include_unexpected_rows = True in the result_format. This will return all the columns of the unexpected rows. However, some columns are datetime, date and decimal which is not JSON Serializable.

Solution:
I have created a Pull Request to fix this. It would be nice if you can review it. Thanks!
#6776

@austiezr
Copy link
Contributor

Closing as resolved by #6776. Thank you! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community devrel This item is being addressed by the Developer Relations Team
Projects
None yet
Development

No branches or pull requests

3 participants