### Setup Dataframely Post-installation and Pre-commit Hooks Source: https://dataframely.readthedocs.io/en/latest/_sources/sites/development.rst Installs the package locally and configures pre-commit hooks for development. ```bash pixi run postinstall pixi run pre-commit-install ``` -------------------------------- ### Install Dataframely Development Environment Source: https://dataframely.readthedocs.io/en/latest/_sources/sites/development.rst Clones the dataframely repository and installs its dependencies using pixi. ```bash git clone https://github.com/Quantco/dataframely cd dataframely pixi install ``` -------------------------------- ### Environment Installation Source: https://dataframely.readthedocs.io/en/latest/sites/development Steps to set up a local development environment for Dataframely. This typically involves navigating to the project directory and installing the package locally along with pre-commit hooks. ```shell cd # Install package locally and set up pre-commit hooks ``` -------------------------------- ### Build and Open Dataframely Documentation Source: https://dataframely.readthedocs.io/en/latest/_sources/sites/development.rst Compiles a localized build of the documentation and opens it in the web browser. ```bash # Run build pixi run -e docs postinstall pixi run docs # Open documentation open docs/_build/html/index.html ``` -------------------------------- ### Install Dataframely with Pixi or Pip Source: https://dataframely.readthedocs.io/en/latest/_sources/sites/installation.rst Install the dataframely package using your preferred package manager. This example shows installation via pixi and pip. ```bash pixi add dataframely pip install dataframely ``` -------------------------------- ### Install Dataframely using Pixi or Pip Source: https://dataframely.readthedocs.io/en/latest/sites/installation Install the Dataframely library using your preferred package manager. The provided commands are for pixi and pip, common tools for managing Python packages and environments. ```shell pixi install dataframely ``` ```shell pip install dataframely ``` -------------------------------- ### Building Documentation Source: https://dataframely.readthedocs.io/en/latest/sites/development Commands to compile a localized build of the Dataframely documentation and open it in a web browser. This is useful when making changes to the documentation content. ```shell # Run build pixi # Open documentation open ``` -------------------------------- ### Configure mypy for Dataframely Plugin Source: https://dataframely.readthedocs.io/en/latest/sites/quickstart Shows the necessary configuration in `pyproject.toml` to enable the `dataframely.mypy` plugin, which is required for static type checking of Dataframely code. ```toml [tool.mypy] plugins = ["dataframely.mypy"] ``` -------------------------------- ### Get DataFrame of Failed Rows Source: https://dataframely.readthedocs.io/en/latest/sites/quickstart Obtains a DataFrame containing only the rows that failed validation against the defined schema. This is useful for detailed analysis or correction of invalid data. ```python failed_df = failure.invalid() ``` -------------------------------- ### Create and Validate Polars DataFrame Source: https://dataframely.readthedocs.io/en/latest/_sources/sites/examples/real-world.ipynb Demonstrates creating a Polars DataFrame with specific data types and validating it against a defined schema using Dataframely. This example shows a successful validation scenario. ```Python from datetime import date, datetime import polars as pl # Assuming InvoiceSchema is defined elsewhere and imported # class InvoiceSchema: # @classmethod # def validate(cls, df, cast=False): # # Placeholder for actual validation logic # print("Validating DataFrame...") # # In a real scenario, this would return validated df and failures # return df, [] invoices = pl.DataFrame({ "invoice_id": ["001", "002", "003"], "admission_date": [date(2025, 1, 1), date(2025, 1, 5), date(2025, 1, 1)], "discharge_date": [date(2025, 1, 4), date(2025, 1, 7), date(2025, 1, 1)], "received_at": [datetime(2025, 1, 5), datetime(2025, 1, 8), datetime(2025, 1, 2)], "amount": [1000.0, 200.0, 400.0] }) # Assuming InvoiceSchema.validate is a method that checks the DataFrame against a schema # InvoiceSchema.validate(invoices, cast=True) # Displaying the created DataFrame (simulating output) print(invoices.to_string()) ``` -------------------------------- ### Creating a Schema class Source: https://dataframely.readthedocs.io/en/latest/sites/quickstart Defines a `HouseSchema` class inheriting from `dataframely.Schema`. It specifies column names, data types (String, UInt8, Float64), and nullability constraints for a housing dataset. ```Python importdataframelyasdy classHouseSchema(dy.Schema): zip_code = dy.String(nullable=False, min_length=3) num_bedrooms = dy.UInt8(nullable=False) num_bathrooms = dy.UInt8(nullable=False) price = dy.Float64(nullable=False) ``` -------------------------------- ### Configure Mypy Plugin Source: https://dataframely.readthedocs.io/en/latest/_sources/sites/quickstart.rst Provides the TOML configuration required to enable the dataframely mypy plugin for type checking code that uses dataframely rules. ```toml [tool.mypy] plugins = ["dataframely.mypy"] ``` -------------------------------- ### Dataframely Schema Integration Methods Source: https://dataframely.readthedocs.io/en/latest/sites/quickstart Provides methods for integrating Dataframely schemas with external tools. Includes creating empty DataFrames, generating SQL schemas, and creating PyArrow schemas. ```APIDOC HouseSchema: create_empty() -> dy.DataFrame[HouseSchema] Creates an empty DataFrame conforming to the HouseSchema, useful for testing. sql_schema() -> list[sqlalchemy.Column] Generates a list of SQLAlchemy Column objects representing the schema, suitable for SQL table creation. pyarrow_schema() -> pyarrow.Schema Returns a PyArrow Schema object that mirrors the Dataframely schema's dtypes and nullability. ``` -------------------------------- ### Define Dataframely Schema Source: https://dataframely.readthedocs.io/en/latest/_sources/sites/quickstart.rst Demonstrates creating a dataframely.Schema subclass to define data expectations for columns, including data types, nullability, and minimum string length. ```python import dataframely as dy class HouseSchema(dy.Schema): zip_code = dy.String(nullable=False, min_length=3) num_bedrooms = dy.UInt8(nullable=False) num_bathrooms = dy.UInt8(nullable=False) price = dy.Float64(nullable=False) ``` -------------------------------- ### Running Tests Source: https://dataframely.readthedocs.io/en/latest/sites/development Instructions for executing the test suite for Dataframely. The path can be adjusted to target specific directories or modules within the tests folder. ```shell test # Adjust 'tests/' path to run tests in a specific directory or module ``` -------------------------------- ### Run Dataframely Tests Source: https://dataframely.readthedocs.io/en/latest/_sources/sites/development.rst Executes the test suite for dataframely. Tests can be run for specific directories or modules by adjusting the path. ```bash pixi run test ``` -------------------------------- ### Import necessary libraries Source: https://dataframely.readthedocs.io/en/latest/_sources/sites/examples/real-world.ipynb Imports the `dataframely` library for data validation, `polars` for data manipulation, and `Decimal`, `datetime`, `date` for data types. ```python import dataframely as dy import polars as pl from decimal import Decimal from datetime import datetime, date ``` -------------------------------- ### Schema Inheritance for DataFrames Source: https://dataframely.readthedocs.io/en/latest/sites/examples/real-world Illustrates how to use schema inheritance in dataframely to reduce redundancy by defining a common base schema for shared fields like primary keys. This example shows inheritance for invoice IDs and defines specific fields and validation rules for `InvoiceSchema` and `DiagnosisSchema`. ```Python # Reduce redundancies in schemas by using schema inheritance. # Here, we introduce a base schema for the shared primary key. class InvoiceIdSchema(dy.Schema): invoice_id = dy.String(primary_key=True) class InvoiceSchema(InvoiceIdSchema): admission_date = dy.Date(nullable=False) discharge_date = dy.Date(nullable=False) received_at = dy.Datetime(nullable=False) amount = dy.Decimal(nullable=False, min_exclusive=Decimal(0)) @dy.rule() def discharge_after_admission() -> pl.Expr: return pl.col("discharge_date") >= pl.col("admission_date") @dy.rule() def received_at_after_discharge() -> pl.Expr: return pl.col("received_at").dt.date() >= pl.col("discharge_date") class DiagnosisSchema(InvoiceIdSchema): diagnosis_code = dy.String(primary_key=True, regex=r"[A-Z][0-9]{2,4}") is_main = dy.Bool(nullable=False) @dy.rule(group_by=["invoice_id"]) def exactly_one_main_diagnosis() -> pl.Expr: return pl.col("is_main").sum() == 1 ``` -------------------------------- ### Inspect Validation Failure Counts Source: https://dataframely.readthedocs.io/en/latest/sites/quickstart Retrieves a dictionary detailing the counts of different validation failure reasons for invalid rows. This helps in understanding the nature and frequency of data quality issues. ```python print(failure.counts()) ``` -------------------------------- ### Python Imports for Dataframely Source: https://dataframely.readthedocs.io/en/latest/sites/examples/real-world Imports necessary libraries including dataframely for schema validation, polars for data manipulation, and Decimal and datetime for data types. ```python importdataframelyasdy importpolarsaspl fromdecimalimport Decimal fromdatetimeimport datetime, date ``` -------------------------------- ### Custom rules for cross-column validation Source: https://dataframely.readthedocs.io/en/latest/sites/quickstart Adds a custom rule `reasonable_bathroom_to_bedrooom_ratio` to the `HouseSchema` using the `@dy.rule()` decorator. The rule checks the ratio between bathrooms and bedrooms, returning a boolean expression for row-wise validation. ```Python importdataframelyasdy import polars as pl classHouseSchema(dy.Schema): zip_code = dy.String(nullable=False, min_length=3) num_bedrooms = dy.UInt8(nullable=False) num_bathrooms = dy.UInt8(nullable=False) price = dy.Float64(nullable=False) @dy.rule() defreasonable_bathroom_to_bedrooom_ratio() -> pl.Expr: ratio = pl.col("num_bathrooms") / pl.col("num_bedrooms") return (ratio >= 1 / 3) & (ratio <= 3) ``` -------------------------------- ### FailureInfo Object Methods Source: https://dataframely.readthedocs.io/en/latest/_sources/sites/quickstart.rst Describes the methods available on the `FailureInfo` object returned by `HouseSchema.filter`. These methods allow detailed inspection of validation failures, including counts and retrieval of invalid rows. ```APIDOC FailureInfo: - Object containing details about validation failures. - Methods: * counts(): Returns a dictionary mapping failure reasons to their occurrence count. Example: { "reasonable_bathroom_to_bedrooom_ratio": 1, "minimum_zip_code_count": 2, "zip_code|min_length": 1, "num_bedrooms|nullability": 2, } * invalid(): Returns a DataFrame containing all rows that failed validation. ``` -------------------------------- ### Validate DataFrame Against Schema Source: https://dataframely.readthedocs.io/en/latest/_sources/sites/quickstart.rst Shows how to use the validate class method of a dataframely.Schema to check a polars DataFrame against the defined rules and optionally cast columns. ```python import polars as pl # Assuming HouseSchema is defined as above df = pl.DataFrame({ "zip_code": ["01234", "01234", "1", "213", "123", "213"], "num_bedrooms": [2, 2, 1, None, None, 2], "num_bathrooms": [1, 2, 1, 1, 0, 8], "price": [100_000, 110_000, 50_000, 80_000, 60_000, 160_000] }) # Validate the data and cast columns to expected types validated_df = HouseSchema.validate(df, cast=True) ``` -------------------------------- ### Create Data Collection Source: https://dataframely.readthedocs.io/en/latest/_sources/sites/examples/real-world.ipynb Introduces a collection for groups of schema-validated data frames by subclassing dy.Collection. This allows for organizing related schemas and defining relationships between them within a single structure. ```Python # Introduce a collection for groups of schema-validated data frames class HospitalClaims(dy.Collection): invoices: dy.LazyFrame[InvoiceSchema] diagnoses: dy.LazyFrame[DiagnosisSchema] ``` -------------------------------- ### Validate DataFrame Against House Schema Source: https://dataframely.readthedocs.io/en/latest/sites/quickstart Illustrates validating a Polars DataFrame against a defined `HouseSchema` using the `validate` method. It includes casting columns to expected types and shows how validation errors are reported via `RuleValidationError`. ```python import polars as pl df = pl.DataFrame({ "zip_code": ["01234", "01234", "1", "213", "123", "213"], "num_bedrooms": [2, 2, 1, None, None, 2], "num_bathrooms": [1, 2, 1, 1, 0, 8], "price": [100_000, 110_000, 50_000, 80_000, 60_000, 160_000] }) # Validate the data and cast columns to expected types validated_df = HouseSchema.validate(df, cast=True) ``` -------------------------------- ### Create Polars DataFrame for Diagnoses Source: https://dataframely.readthedocs.io/en/latest/_sources/sites/examples/real-world.ipynb Shows the creation of a Polars DataFrame named 'diagnoses'. This DataFrame links diagnosis codes to specific invoice IDs, including a flag for the main diagnosis. ```Python diagnoses = pl.DataFrame( { "invoice_id": ["001", "001", "002"], "diagnosis_code": ["A123", "B456", "C789"], "is_main": [True, False, True], } ) ``` -------------------------------- ### Add Grouped Rule for Row Aggregation Source: https://dataframely.readthedocs.io/en/latest/_sources/sites/quickstart.rst Illustrates defining rules that operate on groups of rows, such as ensuring a minimum count per group, using the group_by parameter in the @dy.rule decorator. ```python import dataframely as dy import polars as pl class HouseSchema(dy.Schema): zip_code = dy.String(nullable=False, min_length=3) num_bedrooms = dy.UInt8(nullable=False) num_bathrooms = dy.UInt8(nullable=False) price = dy.Float64(nullable=False) @dy.rule() def reasonable_bathroom_to_bedrooom_ratio() -> pl.Expr: ratio = pl.col("num_bathrooms") / pl.col("num_bedrooms") return (ratio >= 1 / 3) & (ratio <= 3) @dy.rule(group_by=["zip_code"]) def minimum_zip_code_count() -> pl.Expr: return pl.len() >= 2 ``` -------------------------------- ### RuleValidationError Example Source: https://dataframely.readthedocs.io/en/latest/_sources/sites/quickstart.rst Shows the structure of a RuleValidationError, indicating which rules failed validation for specific columns and how many rows were affected. This exception is raised during strict validation. ```APIDOC RuleValidationError: - Indicates validation failures for a DataFrame. - Structure: * Total number of rules failed. * Breakdown by column: - Column name. - Number of rules failed for the column. - List of specific rule failures (e.g., 'nullability', 'min_length') and affected row counts. Example: 2 rules failed validation: * Column 'num_bedrooms' failed validation for 1 rules: - 'nullability' failed for 2 rows * Column 'zip_code' failed validation for 1 rules: - 'min_length' failed for 1 rows ``` -------------------------------- ### Dataframely Schema Integration with External Tools Source: https://dataframely.readthedocs.io/en/latest/_sources/sites/quickstart.rst Details how Dataframely schemas can be leveraged to interact with external systems. This includes creating empty DataFrames for testing, generating SQL table schemas, and producing PyArrow schemas. ```Python # Create an empty DataFrame conforming to the schema empty_df = HouseSchema.create_empty() # Get a list of SQLAlchemy columns based on the schema sql_columns = HouseSchema.sql_schema() # Get a PyArrow schema object from the Dataframely schema pyarrow_schema = HouseSchema.pyarrow_schema() ``` -------------------------------- ### Handle Dataframely Validation Errors Source: https://dataframely.readthedocs.io/en/latest/_sources/sites/examples/real-world.ipynb Illustrates how Dataframely raises a `RuleValidationError` when data fails schema validation, providing details about the violated rules. This example intentionally includes an invalid 'amount' to trigger the error. ```Python from datetime import date, datetime import polars as pl # Placeholder for RuleValidationError and InvoiceSchema class RuleValidationError(Exception): def __init__(self, message): super().__init__(message) class InvoiceSchema: @classmethod def validate(cls, df, cast=False): # Simulate validation failure for 'amount' column with min_exclusive rule failures = { "amount": { "min_exclusive": 1 # Assuming min_exclusive rule is violated } } if any(k in failures for k in df.columns): raise RuleValidationError("1 rules failed validation:\n * Column 'amount' failed validation for 1 rules:\n - 'min_exclusive' failed for 1 rows") return df, [] # Raise during validation if there are invalid rows invoices = pl.DataFrame({ "invoice_id": ["001", "002", "003"], "admission_date": [date(2025, 1, 1), date(2025, 1, 5), date(2025, 1, 1)], "discharge_date": [date(2025, 1, 4), date(2025, 1, 7), date(2025, 1, 1)], "received_at": [datetime(2025, 1, 5), datetime(2025, 1, 8), datetime(2025, 1, 2)], "amount": [0.0, 200.0, 400.0] # Invalid amount `0.0` here }) # This call is expected to raise RuleValidationError # InvoiceSchema.validate(invoices, cast=True) # Example of how the error might be caught and reported try: InvoiceSchema.validate(invoices, cast=True) except RuleValidationError as e: print(f"Caught expected validation error: {e}") ``` -------------------------------- ### Define Grouped Rule for Minimum Zip Code Count Source: https://dataframely.readthedocs.io/en/latest/sites/quickstart Demonstrates using the `@dy.rule` decorator with `group_by` to evaluate rules across rows, such as ensuring a minimum number of houses per zip code. Includes a basic rule for bathroom-to-bedroom ratio. ```python import dataframely as dy import polars as pl class HouseSchema(dy.Schema): zip_code = dy.String(nullable=False, min_length=3) num_bedrooms = dy.UInt8(nullable=False) num_bathrooms = dy.UInt8(nullable=False) price = dy.Float64(nullable=False) @dy.rule() def reasonable_bathroom_to_bedrooom_ratio() -> pl.Expr: ratio = pl.col("num_bathrooms") / pl.col("num_bedrooms") return (ratio >= 1 / 3) & (ratio <= 3) @dy.rule(group_by=["zip_code"]) def minimum_zip_code_count() -> pl.Expr: return pl.len() >= 2 ``` -------------------------------- ### Get Polars Schema Representation Source: https://dataframely.readthedocs.io/en/latest/_api/dataframely.testing Obtains the Polars schema representation for the current schema. This method is useful for interoperability with the Polars library. ```APIDOC polars_schema() → Schema[[source]](https://github.com/quantco/dataframely/blob/026dfb316d776d59ddf526b6f604900dd3df1ae6/dataframely/schema.py#L897-L904) Obtain the polars schema for this schema. Returns: A `polars` schema that mirrors the schema defined by this class. ``` -------------------------------- ### Get PyArrow Schema Source: https://dataframely.readthedocs.io/en/latest/_api/dataframely.testing.typing Obtains the PyArrow schema representation for this schema. This facilitates interoperability with libraries that use PyArrow for schema management. ```APIDOC _classmethod_ pyarrow_schema() → pa.Schema[[source]](https://github.com/quantco/dataframely/blob/026dfb316d776d59ddf526b6f604900dd3df1ae6/dataframely.py#L922-L931) Obtain the pyarrow schema for this schema. Returns: A `pyarrow` schema that mirrors the schema defined by this class. ``` -------------------------------- ### Get Polars Schema Source: https://dataframely.readthedocs.io/en/latest/_api/dataframely.testing.typing Obtains the Polars schema representation for this schema. This method is useful for integrating Dataframely schemas with Polars DataFrame operations. ```APIDOC _classmethod_ polars_schema() → Schema[[source]](https://github.com/quantco/dataframely/blob/026dfb316d776d59ddf526b6f604900dd3df1ae6/dataframely.py#L897-L904) Obtain the polars schema for this schema. Returns: A `polars` schema that mirrors the schema defined by this class. ``` -------------------------------- ### dataframely.collection.Collection Class Methods Source: https://dataframely.readthedocs.io/en/latest/_api/dataframely.collection This entry groups all documented methods belonging to the Collection class within the dataframely.collection module. The provided text lists method names and links to their specific API documentation pages, but does not include detailed signatures, parameter descriptions, return values, or usage examples within this context. Further details for each method would typically be found at the linked API documentation URLs. ```APIDOC dataframely.collection.Collection: Methods: cast() collect_all() common_primary_keys() create_empty() filter() ignored_members() is_valid() matches() member_schemas() members() non_ignored_members() optional_members() read_parquet() required_members() sample() scan_parquet() serialize() sink_parquet() to_dict() validate() write_parquet() ``` -------------------------------- ### Get PyArrow Schema Representation Source: https://dataframely.readthedocs.io/en/latest/_api/dataframely.testing Obtains the PyArrow schema representation for the current schema. This method facilitates integration with libraries that use PyArrow schemas. ```APIDOC pyarrow_schema() → pa.Schema[[source]](https://github.com/quantco/dataframely/blob/026dfb316d776d59ddf526b6f604900dd3df1ae6/dataframely/schema.py#L922-L931) Obtain the pyarrow schema for this schema. Returns: A `pyarrow` schema that mirrors the schema defined by this class. ``` -------------------------------- ### Dataframely API Documentation Overview Source: https://dataframely.readthedocs.io/index Provides an overview of the Dataframely API modules, covering collections, column types, configuration, random data generation, failure information, and schema validation. This entry serves as a reference point for the library's API structure. ```APIDOC Dataframely API Modules: - Collection: Documentation for collection-related functionalities. - Column Types: Details on column type definitions and validation. - Config: Information on configuration options and settings. - Random Data Generation: API for generating test data that complies with schemas. - Failure Information: Details on how to introspect and handle validation failures. - Schema: Documentation for defining and validating data frame schemas. ``` -------------------------------- ### Get Primary Keys Source: https://dataframely.readthedocs.io/en/latest/_api/dataframely.testing.typing Retrieves a list of column names that are designated as primary keys within this schema. This is useful for identifying unique identifiers in the data. ```APIDOC _classmethod_ primary_keys() → list[str][[source]](https://github.com/quantco/dataframely/blob/026dfb316d776d59ddf526b6f604900dd3df1ae6/_base_schema.py#L186-L189) The primary key columns in this schema (possibly empty). ``` -------------------------------- ### Dataframely API Documentation Overview Source: https://dataframely.readthedocs.io/en/latest Provides an overview of the Dataframely API modules, covering collections, column types, configuration, random data generation, failure information, and schema validation. This entry serves as a reference point for the library's API structure. ```APIDOC Dataframely API Modules: - Collection: Documentation for collection-related functionalities. - Column Types: Details on column type definitions and validation. - Config: Information on configuration options and settings. - Random Data Generation: API for generating test data that complies with schemas. - Failure Information: Details on how to introspect and handle validation failures. - Schema: Documentation for defining and validating data frame schemas. ``` -------------------------------- ### Get Required Members of Collection Source: https://dataframely.readthedocs.io/en/latest/_api/dataframely.collection Returns the names of all required members of the collection. This method is a classmethod and provides a set of strings representing the member names. ```APIDOC Collection.required_members() -> set[str] Returns: A set containing the names of all required members of the collection. ``` -------------------------------- ### Typed DataFrame Usage for Static Analysis Source: https://dataframely.readthedocs.io/en/latest/_sources/sites/quickstart.rst Demonstrates how to use Dataframely's typed DataFrames with schemas for static type checking, ensuring functions receive data frames conforming to expected structures. This improves code readability and maintainability. ```Python def train_model(df: dy.DataFrame[HouseSchema]) -> None: # df is guaranteed to conform to HouseSchema by the type checker ... # Type checker will flag calls with incorrect DataFrame types ``` -------------------------------- ### Get Primary Key Columns Source: https://dataframely.readthedocs.io/en/latest/_api/dataframely.testing Retrieves a list of column names designated as primary keys within this schema. The list may be empty if no primary keys are defined. ```APIDOC primary_keys() → list[str][[source]](https://github.com/quantco/dataframely/blob/026dfb316d776d59ddf526b6f604900dd3df1ae6/dataframely/_base_schema.py#L186-L189) The primary key columns in this schema (possibly empty). Returns: The primary key columns in this schema (possibly empty). ``` -------------------------------- ### Add column constraints to invoice schema Source: https://dataframely.readthedocs.io/en/latest/_sources/sites/examples/real-world.ipynb Enhances the invoice schema by adding column constraints such as primary key, nullability, and minimum value for the amount. ```python class InvoiceSchema(dy.Schema): invoice_id = dy.String(primary_key=True) admission_date = dy.Date(nullable=False) discharge_date = dy.Date(nullable=False) received_at = dy.Datetime(nullable=False) amount = dy.Decimal(nullable=False, min_exclusive=Decimal(0)) ``` -------------------------------- ### Dataframely Options Class API Source: https://dataframely.readthedocs.io/en/latest/_api/dataframely.config API documentation for the `Options` class, which manages various configuration parameters within dataframely. Includes methods for manipulation and access. ```APIDOC Options: clear(): Removes all items from the options. copy(): Returns a shallow copy of the options. fromkeys(seq, value=None): Creates a new dictionary with keys from seq and values set to value. get(key, default=None): Returns the value for key if key is in the dictionary, else default. items(): Returns a view object that displays a list of a dictionary's key-value tuple pairs. keys(): Returns a view object that displays a list of all the keys in the dictionary. max_sampling_iterations: The maximum number of sampling iterations. pop(key, default=...): Removes the specified key and returns the corresponding value. popitem(): Removes and returns a (key, value) pair from the dictionary. setdefault(key, default=None): Inserts key with a value of default if key is not in the dictionary. update(other=None, **kwargs): Updates the dictionary with the key/value pairs from other, overwriting existing keys. values(): Returns a view object that displays a list of all the values in the dictionary. ``` -------------------------------- ### Validate a data frame with schema Source: https://dataframely.readthedocs.io/en/latest/_sources/sites/examples/real-world.ipynb Validates a `pl.DataFrame` or `pl.LazyFrame` against a defined `dataframely` schema. The `cast=True` option attempts to coerce column types to match the schema. ```python invoice_df = pl.DataFrame({ "invoice_id": ["001", "002", "003"], "admission_date": [date(2025, 1, 1), date(2025, 1, 5), date(2025, 1, 1)], "discharge_date": [date(2025, 1, 4), date(2025, 1, 7), date(2025, 1, 1)], "received_at": [datetime(2025, 1, 5), datetime(2025, 1, 8), datetime(2025, 1, 2)], "amount": [Decimal(1000), Decimal(200), Decimal(400)] }) validated_df = InvoiceSchema.validate(invoice_df, cast=True) ``` -------------------------------- ### Dataframely Collection Class Methods Source: https://dataframely.readthedocs.io/en/latest/_api/dataframely.collection API documentation for various class methods of the dataframely.collection.Collection class, including data collection, filtering, and initialization. ```APIDOC dataframely.collection.Collection: collect_all() -> Self Collects all members of the collection in parallel for maximum efficiency. Useful when filter() is called with lazy frame inputs. Returns: The same collection with all members collected once, but still "shallow-lazy". common_primary_keys() -> list[str] Class method to retrieve the primary keys shared by non-ignored members of the collection. create_empty() -> Self Class method to create an empty collection without any data. Calls `create_empty` on all member schemas. Returns: An instance of this collection. filter(_data: Mapping[str, FrameType], _, *_, cast: bool = False) -> tuple[Self, dict[str, FailureInfo]] Filters members data frame by their schemas and collection's filters. Args: _data: Dictionary containing members of the collection to be filtered. Must contain exactly one entry per member (key is member name). cast: If True, casts columns with wrong data types to schema-defined types if possible. Returns: A tuple containing: - An instance of the collection with filtered data (members are eager). - A mapping from member name to FailureInfo detailing why rows were removed. Raises: ValueError: If an insufficient set of input data frames is provided. ValidationError: If input data frame columns are invalid (missing or wrong dtype when cast=False). ignored_members() -> set[str] Retrieves the names of all members of the collection that are ignored in filters. ``` -------------------------------- ### dataframely.collection.deserialize_collection Function Source: https://dataframely.readthedocs.io/en/latest/_api/dataframely.collection Documentation for the deserialize_collection function within the dataframely.collection module. The provided text links to its API documentation page, but does not include its signature, parameter descriptions, return values, or usage examples. ```APIDOC dataframely.collection.deserialize_collection() ``` -------------------------------- ### Create Polars DataFrame for Invoices Source: https://dataframely.readthedocs.io/en/latest/_sources/sites/examples/real-world.ipynb Demonstrates the creation of a Polars DataFrame named 'invoices'. This DataFrame includes columns for invoice details such as ID, admission, discharge dates, received timestamp, and amount. ```Python invoices = pl.DataFrame( { "invoice_id": ["001", "002", "003"], "admission_date": [date(2025, 1, 1), date(2025, 1, 5), date(2025, 1, 1)], "discharge_date": [date(2025, 1, 4), date(2025, 1, 7), date(2025, 1, 1)], "received_at": [ datetime(2025, 1, 5), datetime(2025, 1, 8), datetime(2025, 1, 2), ], "amount": [1000.0, 200.0, 400.0], } ) ```