great-expectations について
検証付きデータパイプラインを構築するデータエンジニア向けの Great Expectations スキルです。Expectation の定義、チェックポイント検証、HTML の Data Docs 生成に関する手順を提供します。
主な機能
- 01Pandas コンテキストとアセットの作成
- 02基本 Expectation Suite の設定
- 03チェックポイント検証の実行
- 04HTML Data Docs の生成
活用シーン
- 01データパイプラインのテーブルと列の検証
- 02NULL、範囲、一意性、パターンの確認
- 03検証結果のドキュメント化
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ majesticlabs-dev/ majestic-marketplace --skill great-expectationsインストール後、Claude Code で/great-expectationsを入力して読み込まれたか確認します。
同梱ファイルscripts/expectations.py
詳細
Great Expectations
対象読者: 検証済みのデータパイプラインを構築するデータエンジニア。
目標: 期待値ベースの検証とモニタリングに関する GX のパターンを提供します。
スクリプト
scripts/expectations.py の GX 関数を実行します:
from scripts.expectations import (
get_pandas_context,
add_dataframe_asset,
create_basic_suite,
run_validation
)
使用例
クイックセットアップ
from scripts.expectations import get_pandas_context, add_dataframe_asset
context, datasource = get_pandas_context("my_datasource")
batch_request = add_dataframe_asset(datasource, "users", df)
期待値スイートの作成
from scripts.expectations import create_basic_suite
columns_config = {
'user_id': {'not_null': True, 'unique': True, 'type': 'int'},
'age': {'min': 0, 'max': 150},
'status': {'values': ['active', 'inactive', 'pending']},
'email': {'regex': r'^[\w\.-]+@[\w\.-]+\.\w+$'}
}
suite = create_basic_suite(context, "user_suite", columns_config)
検証の実行
from scripts.expectations import run_validation
results = run_validation(
context,
checkpoint_name="user_checkpoint",
batch_request=batch_request,
suite_name="user_suite"
)
if results['success']:
print("All expectations passed!")
else:
for failure in results['failures']:
print(f"Failed: {failure['expectation']} on {failure['column']}")
一般的な期待値のリファレンス
| カテゴリ | 期待値 | 説明 |
|---|---|---|
| テーブル | ExpectTableRowCountToBeBetween | 行数の範囲 |
| 存在 | ExpectColumnToExist | 列が存在する必要があります |
| NULL 値 | ExpectColumnValuesToNotBeNull | NULL 値がないこと |
| 範囲 | ExpectColumnValuesToBeBetween | 値の範囲 |
| セット | ExpectColumnValuesToBeInSet | 許可される値 |
| パターン | ExpectColumnValuesToMatchRegex | 正規表現との一致 |
| 一意性 | ExpectColumnValuesToBeUnique | 重複がないこと |
データドキュメント
# Build and open HTML reports
context.build_data_docs()
context.open_data_docs()
ディレクトリ構成
great_expectations/
├── great_expectations.yml # Config
├── expectations/ # Expectation suites (JSON)
├── checkpoints/ # Checkpoint definitions
├── plugins/ # Custom expectations
└── uncommitted/
├── data_docs/ # Generated HTML docs
└── validations/ # Validation results
Great Expectations を使用する場面
| ユースケース | GX | 代替手段 |
|---|---|---|
| パイプラインのモニタリング | ✓ | - |
| データウェアハウスの検証 | ✓ | - |
| データドキュメントの自動生成 | ✓ | - |
| シンプルな DataFrame のチェック | - | Pandera |
| レコードレベルの API 検証 | - | Pydantic |
依存関係
great_expectations>=0.18
pandas
コメント
Markdown 対応