0

Great Expectations v3 api: expect_column_values_to_be_positive を使用して、非常に単純な期待値を作成しようとしています。私は PandasExecutionEngine を使用しており、データ アセットは pandas データフレームです。

my_custom_expectation.py は plugins/ フォルダーにあります。

my_custom_expectation.py のコードは次のとおりです。

from great_expectations.execution_engine import (
     PandasExecutionEngine,
)
from great_expectations.expectations.metrics import (
    ColumnMapMetricProvider,
    column_condition_partial
)
from great_expectations.expectations.expectation import (
    ColumnMapExpectation,
)


def check_positive(value):
    if value:
        return True if value > 0 else False
    return True


class ColumnValueIsPositive(ColumnMapMetricProvider):
    condition_metric_name = "column_values.to_be_positive"

    @column_condition_partial(engine=PandasExecutionEngine)
    def _pandas(cls, column, **kwargs):
        return column.apply(lambda x: check_positive(x))


class ExpectColumnValuesToBePositive(ColumnMapExpectation):
    map_metric = "column_values.to_be_positive"

次に、jupyter ノートブックで、期待値を作成しようとします。

from my_custom_expectation import ExpectColumnValuesToBePositive

validator.expect_column_values_to_be_positive(column="duration")

ただし、次のエラーが表示されます。

TypeError                                 Traceback (most recent call last)
/tmp/ipykernel_5957/859745029.py in <module>
----> 1 validator.expect_column_values_to_be_positive(column="duration")

~/.local/share/virtualenvs/ge-YbASoQtb/lib/python3.8/site-packages/great_expectations/validator/validator.py in inst_expectation(*args, **kwargs)
    285 
    286                 else:
--> 287                     raise err
    288             return validation_result
    289 

~/.local/share/virtualenvs/ge-YbASoQtb/lib/python3.8/site-packages/great_expectations/validator/validator.py in inst_expectation(*args, **kwargs)
    240                     )
    241                 else:
--> 242                     validation_result = expectation.validate(
    243                         validator=self,
    244                         evaluation_parameters=self._expectation_suite.evaluation_parameters,

~/.local/share/virtualenvs/ge-YbASoQtb/lib/python3.8/site-packages/great_expectations/expectations/expectation.py in validate(self, validator, configuration, evaluation_parameters, interactive_evaluation, data_context, runtime_configuration)
    631             evaluation_parameters, interactive_evaluation, data_context
    632         )
--> 633         evr = validator.graph_validate(
    634             configurations=[configuration],
    635             runtime_configuration=runtime_configuration,

~/.local/share/virtualenvs/ge-YbASoQtb/lib/python3.8/site-packages/great_expectations/validator/validator.py in graph_validate(self, configurations, metrics, runtime_configuration)
    499                 return evrs
    500             else:
--> 501                 raise err
    502 
    503         for configuration in processed_configurations:

~/.local/share/virtualenvs/ge-YbASoQtb/lib/python3.8/site-packages/great_expectations/validator/validator.py in graph_validate(self, configurations, metrics, runtime_configuration)
    477         # an exception occurring as part of resolving the combined validation graph impacts all expectations in suite.
    478         try:
--> 479             self.resolve_validation_graph(
    480                 graph=graph,
    481                 metrics=metrics,

~/.local/share/virtualenvs/ge-YbASoQtb/lib/python3.8/site-packages/great_expectations/validator/validator.py in resolve_validation_graph(self, graph, metrics, runtime_configuration)
    555 
    556             metrics.update(
--> 557                 self._resolve_metrics(
    558                     execution_engine=self._execution_engine,
    559                     metrics_to_resolve=ready_metrics,

~/.local/share/virtualenvs/ge-YbASoQtb/lib/python3.8/site-packages/great_expectations/validator/validator.py in _resolve_metrics(execution_engine, metrics_to_resolve, metrics, runtime_configuration)
    603         """A means of accessing the Execution Engine's resolve_metrics method, where missing metric configurations are
    604         resolved"""
--> 605         return execution_engine.resolve_metrics(
    606             metrics_to_resolve=metrics_to_resolve,
    607             metrics=metrics,

~/.local/share/virtualenvs/ge-YbASoQtb/lib/python3.8/site-packages/great_expectations/execution_engine/execution_engine.py in resolve_metrics(self, metrics_to_resolve, metrics, runtime_configuration)
    283                 # than data to optimize compute in the future
    284                 try:
--> 285                     resolved_metrics[metric_to_resolve.id] = metric_fn(
    286                         **metric_provider_kwargs
    287                     )

~/.local/share/virtualenvs/ge-YbASoQtb/lib/python3.8/site-packages/great_expectations/expectations/metrics/metric_provider.py in inner_func(*args, **kwargs)
     53         @wraps(metric_fn)
     54         def inner_func(*args, **kwargs):
---> 55             return metric_fn(*args, **kwargs)
     56 
     57         inner_func.metric_engine = engine

~/.local/share/virtualenvs/ge-YbASoQtb/lib/python3.8/site-packages/great_expectations/expectations/metrics/map_metric_provider.py in inner_func(cls, execution_engine, metric_domain_kwargs, metric_value_kwargs, metrics, runtime_configuration)
    326                     df = df[df[column_name].notnull()]
    327 
--> 328                 meets_expectation_series = metric_fn(
    329                     cls,
    330                     df[column_name],

TypeError: _pandas() got an unexpected keyword argument '_metrics'

何か不足していますか?この例に従って、期待/メトリックを記述しました。

4

1 に答える 1