Temporian

repository·main·Indexed 20 days ago

https://github.com/google/temporian

A Python library for safe, simple, and efficient preprocessing and feature engineering of temporal data. Optimized for multivariate time-series, event logs, and cross-source event streams, Temporian provides a specialized counterpart to Pandas for managing EventSets—multivariate, multi-index time sequences. It includes tools for moving window aggregations, calendar-based ticking, resampling, and seamless integration with pandas DataFrames.

Tokens
24.9K
Snippets
115
Records
137
Agent score
71%

What's inside temporian

  1. Core Classes in Temporian

    main

    Temporian's core abstractions are centered around data containers and their structural descriptions:

    • tp.EventSet: The primary container for actual temporal data.
    • tp.EventSetNode: A reference to the input or output of an operator within a compute graph.
    • tp.Schema: Describes the data structure contained within an EventSet or EventSetNode.
    • tp.FeatureSchema: Describes an individual feature within a Schema.
    • tp.IndexSchema: Describes an index within a Schema.
  2. Explore Temporian tutorials for practical use cases

    main

    Temporian provides several specialized tutorials for different domains and technical workflows. Before diving into these, it is recommended to review the Getting Started guide to understand core concepts like sampling and indexes.

    Available tutorial scenarios include:

  3. Follow docstring guidelines for Temporian's public API

    main

    When contributing to Temporian, follow these guidelines for writing docstrings for the public API to ensure consistency and clarity. The objective is to provide succinct, accurate, and unambiguous technical reference material.

    General Principles

    • Austere and To the point: Avoid flowery language; docstrings should only describe.
    • Descriptive, not Imperative: Use """Shifts the sampling backwards""" instead of """Shift the sampling backwards""".
    • No Noun Prefixes: Avoid """Function that shifts...""" or """Operator that shifts...""".
    • Avoid Redundancy: Do not write docstrings that provide no new information (e.g., """Test for lag operator.""").

    Structure

    Use the three-double-quote """ format:

    1. A summary line (max 80 chars) terminated by a period.
    2. A blank line.
    3. The rest of the docstring content.

    Every file should also contain license boilerplate.

  4. Build Temporian for Linux using manylinux2014

    main

    To ensure maximum compatibility across Linux distributions, build Temporian within a manylinux2014 container. The project uses a TFX manylinux Docker image that includes Bazel.

    1. Start the Docker container:
      ./tools/start_compile_docker.sh
    2. Inside the container, execute the build script for your target Python version:
      PYTHON_VERSION=<version> ./tools/build_manylinux.sh
      Replace <version> with one of: 38, 39, 310, or 311.

    Successful builds will be placed in the dist/ directory at the root of the Temporian repository.

    ./tools/start_compile_docker.sh
    # Inside docker:
    PYTHON_VERSION=310 ./tools/build_manylinux.sh
  5. Document modules in Temporian

    main

    A module's docstring should describe its contents and usage. While not currently mandatory in Temporian, it is recommended for public modules.

    Structure

    1. A one-line summary terminated by a period.
    2. A blank line.
    3. An overall description of the module.
    4. (Optional) A brief description of exported classes/functions and usage examples.

    To ensure mkdocs renders examples correctly as dropdowns, indent the content after the Example: clause and use triple backticks (```) for code blocks.

    Example

        """A one-line summary of the module, terminated by a period.
    
        Leave one blank line.  The rest of this docstring should contain an
        overall description of the module.  Optionally, it may also contain a brief
        description of exported classes and functions and/or usage examples.
    
        Example:
            ```python
            foo = ClassFoo()
            bar = foo.FunctionBar()
            ```
        """
  6. Document classes in Temporian

    main

    Classes should have a docstring placed immediately below the class definition. If the class has public attributes, document them in an Attributes: section using the same formatting as the Args: section for functions.

    Example

        """Summary of class here.
    
        Longer class information...
        Longer class information...
    
        Attributes:
            likes_spam: Boolean indicating if we like SPAM or not.
            eggs: Integer count of the eggs we have laid.
        """
  7. Aggregate events by timestamp

    main

    Temporian provides several patterns for aggregating events based on temporal properties. Common use cases include:

    • Calendar features: Aggregating events by specific calendar components like month or year.
    • Fixed-length intervals: Converting discrete events into time-series data by grouping them into regular intervals.
    • Different indexes: Aggregating events that are indexed by different keys.
    • Duplicate timestamps: Unifying multiple events that share the exact same timestamp.
  8. Document functions and methods in Temporian

    main

    Docstrings are mandatory for any function that is part of the public API, has non-trivial size, or contains non-obvious logic.

    Special Sections

    Use the following sections for detailed documentation. Each section heading must end with a colon, and content must be indented by 4 spaces.

    Args:

    • List each parameter by name.
    • Do not document the expected type (use type hints instead).
    • Format: name: description.
    • If a description exceeds the line length, indent the next line by an additional 4 spaces.
    • Include *args and **kwargs if present.
    • Omit unnecessary prepositions like The or A at the start of descriptions.

    Returns: (or Yields: for generators)

    • Describe the semantics of the return value.
    • Do not document the expected return type.
    • Do not include this section if the function returns None.
    • For tuples, use: Returns: A tuple (a, b) where a is....

    Raises:

    • List and describe all exceptions relevant to the interface.
    • Do not document exceptions raised if the API is violated (e.g., invalid argument types).

    Example

        """Fetches rows from a Smalltable.
    
        Retrieves rows pertaining to the given keys from the Table instance
        represented by table_handle.  String keys will be UTF-8 encoded.
    
        Example:
            ```python
            rows = fetch_rows(handle, keys)
            ```
    
        Args:
            table_handle: Open `smalltable.Table` instance.
            keys: Sequence of strings representing the key of each table row to
                fetch. String keys will be UTF-8 encoded.
            require_all_keys: If `True`,  only rows with values set for all keys
                will be returned.
    
        Returns:
            Dict mapping keys to the corresponding table row data fetched. Each row
                is represented as a tuple of strings.
    
        Raises:
            IOError: An error occurred accessing the smalltable.
        """
  9. Build Temporian for macOS

    main

    To build for macOS, ensure you have the desired Python version activated (e.g., via pyenv) and poetry installed. Run the standard Poetry build command:

    poetry build

    Note: You must perform separate builds for ARM64 and Intel architectures to support both types of Mac hardware.