great_expectations icon indicating copy to clipboard operation
great_expectations copied to clipboard

StoreMetricsAction fails with some metrics (statistics.successful_expectations, statistics.unsuccessful_expectations and column based metrics)

Open hoavho opened this issue 1 year ago • 0 comments

Test Environment

  • great_expectations version = 0.15.17
  • python version = Python 3.9.13
  • postgreSQL version = PostgreSQL 14.4 on x86_64-apple-darwin21.5.0, compiled by Apple clang version 13.1.6 (clang-1316.0.21.2.5), 64-bit
  • Configuration is based on example in this article https://docs.greatexpectations.io/docs/guides/setup/configuring_metadata_stores/how_to_configure_a_metricsstore/

Expected Result

  • All requested_metrics are captured and stored to DB (PostgreSQL) correctly

Actual Result

Only some metrics are saved successfully which are

  1. Table based metric (expect_table_row_count_to_be_between.result.observed_value)
  2. statistics metrics (statistics.evaluated_expectations, statistics.success_percent)

Following metrics will fail (causing the app to crash)

  1. statistics metrics (statistics.unsuccessful_expectations and statistics.successful_expectations)
  2. column based metrics (expect_column_max_to_be_between.result.observed_value)

The exception is Object of type int64 is not JSON serializable

packages/great_expectations/data_context/store/metric_store.py", line 64, in serialize
    return json.dumps({"value": value})
  File "/usr/local/Cellar/[email protected]/3.9.13_2/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "/usr/local/Cellar/[email protected]/3.9.13_2/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/local/Cellar/[email protected]/3.9.13_2/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/usr/local/Cellar/[email protected]/3.9.13_2/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type int64 is not JSON serializable

Checkpoint Configuration

Config that works

This config works. And metrics are saved to PostgreSQL correctly

name: base_checkpoint
config_version: 1.0
template_name:
module_name: great_expectations.checkpoint
class_name: Checkpoint
run_name_template: '%Y%m%d-%H%M%S-base-checkpoint'
....
action_list:
  - name: store_validation_result
    action:
      class_name: StoreValidationResultAction
  - name: store_evaluation_params
    action:
      class_name: StoreEvaluationParametersAction
  - name: store_metrics
    action:
      class_name: StoreMetricsAction
      target_store_name: metrics_store
      requested_metrics:
        "getting_started_expectation_suite_taxi.demo":
          - expect_table_row_count_to_be_between.result.observed_value
        "*":  # wildcard to match any expectation suite
          - statistics.evaluated_expectations
          - statistics.success_percent
  - name: update_data_docs
    action:
      class_name: UpdateDataDocsAction

Note: part of irrelevant config is removed to keep it short (Only action_list part is relevant)

Config that fails

This config will fail and cause the app to crash

name: base_checkpoint
config_version: 1.0
template_name:
module_name: great_expectations.checkpoint
class_name: Checkpoint
run_name_template: '%Y%m%d-%H%M%S-base-checkpoint'
expectation_suite_name:
batch_request: {}
action_list:
  - name: store_validation_result
    action:
      class_name: StoreValidationResultAction
  - name: store_evaluation_params
    action:
      class_name: StoreEvaluationParametersAction
  - name: store_metrics
    action:
      class_name: StoreMetricsAction
      target_store_name: metrics_store
      requested_metrics:
        "getting_started_expectation_suite_taxi.demo":
          - expect_table_row_count_to_be_between.result.observed_value
          - column:
              passenger_count:
                - expect_column_max_to_be_between.result.observed_value
        "*":  # wildcard to match any expectation suite
          - statistics.evaluated_expectations
          - statistics.success_percent
          - statistics.successful_expectations
  - name: update_data_docs
    action:
      class_name: UpdateDataDocsAction
evaluation_parameters: {}

hoavho avatar Aug 11 '22 00:08 hoavho