PyDeequ Documentation

repository·master·Indexed 21 days ago

https://github.com/awslabs/python-deequ

PyDeequ is a Python API for Deequ, a library built on Apache Spark for defining 'unit tests for data' to measure data quality in large datasets. It provides tools for computing data metrics via Analyzers, performing data profiling with ColumnProfilerRunner, suggesting constraints via ConstraintSuggestionRunner, and validating data using VerificationSuite and Check objects. The library also supports anomaly detection strategies, row-level result extraction, and persisting metrics using FileSystemMetricsRepository or InMemoryMetricsRepository.

Tokens
37.2K
Snippets
118
Records
155
Agent score
70%

What's inside pydeequ

  1. Interpret Column Profile types

    master

    PyDeequ provides specialized classes to handle different data types within a profile:

    • StandardColumnProfile: General purpose column profile.
    • StringColumnProfile: Specialized profile for string-type columns.
    • NumericColumnProfile: Specialized profile for numeric-type columns.
  2. Use AnalysisRunner and AnalysisRunBuilder to run analyzers

    master

    To perform data analysis in PyDeequ, you use the AnalysisRunBuilder to configure your analysis and the AnalysisRunner to execute it.

    1. Use AnalysisRunBuilder.addAnalyzer(analyzer) to add specific statistical analyzers to your run.
    2. Use AnalysisRunBuilder.useRepository(repository) to specify where results should be stored.
    3. Use AnalysisRunBuilder.saveOrAppendResult(resultKey) to define the key for saving or appending results.
    4. Call AnalysisRunBuilder.run() to execute the analysis.
    5. Use AnalysisRunner.onData(DataFrame) to provide the Spark DataFrame to be analyzed.
  3. Properly shut down PySpark after using PyDeequ

    master

    To prevent hanging processes, ensure you shut down the Spark session and the Spark context gateway callback server after your jobs are complete.

    spark.sparkContext._gateway.shutdown_callback_server()
    spark.stop()
  4. Configure a Glue Development Endpoint for PyDeequ

    master

    When creating or modifying a Glue Development Endpoint to support PyDeequ, you must specify the S3 locations for the libraries in the following fields:

    • Python Library Path: Set this to the S3 path of your pydeequ.zip file.
    • Dependant Jars Path: Set this to the S3 path of your Deequ library (the JAR file).

    Ensure that the IAM role associated with AWS Glue has the necessary permissions to access these S3 paths.

  5. Set up a PySpark session for PyDeequ

    master

    To use PyDeequ, you must initialize a SparkSession configured with the necessary Deequ Maven coordinates to ensure the underlying Scala/Java libraries are available. Use pydeequ.deequ_maven_coord and pydeequ.f2j_maven_coord for configuration.

    from pyspark.sql import SparkSession, Row
    import pydeequ
    
    spark = (SparkSession
        .builder
        .config("spark.jars.packages", pydeequ.deequ_maven_coord)
        .config("spark.jars.excludes", pydeequ.f2j_maven_coord)
        .getOrCreate())
    
    # Example DataFrame
    df = spark.sparkContext.parallelize([
                Row(a="foo", b=1, c=5),
                Row(a="bar", b=2, c=6),
                Row(a="baz", b=3, c=None)]).toDF()