Skip to main content

Utils to work with iterables

Project description

tu

Utils to work with iterables

To install: pip install tu

Overview

The tu package provides a collection of utility functions designed to simplify and enhance the manipulation and analysis of iterables in Python. It includes tools for handling operations such as running means, chunking, sliding windows, and various methods for iterating with specific conditions. This package is especially useful for data processing tasks where complex iterable manipulations are required.

Features

  • Running Mean Calculation: Compute running or moving averages over an iterable, useful for smoothing out time series data.
  • Chunking and Sliding Windows: Generate chunks or sliding windows from an iterable, which is useful for batch processing or moving window analyses.
  • Unique Elements: Extract unique elements from an iterable while preserving order.
  • Sampling: Functions for sampling elements from an iterable based on various criteria.
  • Iterative Tools: A variety of functions to extend Python's built-in itertools, including capabilities to handle padding, repeating, and more complex iteration patterns.

Usage Examples

Running Mean

Calculate the running mean of a sequence with a specified window size:

from tu import running_mean

# Calculate running mean with a window size of 2
result = list(running_mean([1, 3, 5, 7, 9], 2))
print(result)  # Output: [2.0, 4.0, 6.0, 8.0]

Chunking

Divide a list into chunks of a specified size:

from tu import fast_chunker

# Chunk a range of numbers into chunks of size 3
result = list(fast_chunker(range(1, 10), 3))
print(result)  # Output: [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

Unique Elements

Retrieve unique elements from an iterable:

from tu import unique_everseen

# Get unique letters, preserving order
result = list(unique_everseen('AAAABBBCCDAABBB'))
print(result)  # Output: ['A', 'B', 'C', 'D']

Sampling

Randomly sample elements from an iterator:

from tu import random_subset

# Randomly sample 3 elements from a range
result = random_subset(range(100), 3)
print(result)  # Output: [23, 42, 76] (example output, actual may vary)

Detailed Function/Class Documentation

running_mean

Calculates the running mean over an iterable. It can handle arbitrary iterables including lists and generators. This function is particularly useful for signal processing and time series analysis.

fast_chunker

Efficiently chunks an iterable into specified sizes. This is useful for dividing data into manageable pieces, for instance, when processing large datasets that do not fit into memory.

unique_everseen

Extracts unique elements from an iterable, remembering all elements that have been seen. This function is useful for deduplication tasks while maintaining the order of elements.

random_subset

Implements reservoir sampling to obtain a subset of elements from an iterator. This method is useful when the size of the data is unknown or too large to fit into memory.

For more detailed examples and a complete list of all available functions, please refer to the module's documentation strings embedded within the code.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tu-0.0.5-py3-none-any.whl (16.0 kB view details)

Uploaded Python 3

File details

Details for the file tu-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: tu-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 16.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.13

File hashes

Hashes for tu-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 faaa78f99c5882644a0f0f94204af372628270a64c2a0a0648e5a299e44c628d
MD5 703cba3223b4da51a1624e0ebb8010fd
BLAKE2b-256 cc8604d12c98689f48d610775ee6e330f88b658a22a8901c4abd9ca3657d4e1a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page