Skip to main content

Type Inference and Conversion Library for Python

Project description

splurge-typer

Type Inference and Conversion Library for Python

License: MIT

splurge-typer is a comprehensive Python library for inferring data types from string values and converting between different data representations. It can analyze individual string values or entire collections to determine the most appropriate Python data type.

Features

  • Single Value Inference: Automatically detect the data type of individual string values
  • Collection Analysis: Analyze sequences of values to determine dominant types
  • Type Conversion: Convert strings to their inferred Python types
  • Comprehensive Type Support: Handles integers, floats, booleans, dates, times, datetimes, and more
  • Performance Optimized: Includes incremental processing for large datasets
  • Flexible Parsing: Supports multiple date/time formats and handles edge cases

Installation

# Clone the repository
git clone https://github.com/jim-schilling/splurge-typer.git
cd splurge-typer

# Install in development mode
pip install -e .

Quick Start

Basic Usage

from splurge_typer import TypeInference, DataType

# Create a type inference instance
ti = TypeInference()

# Single value inference
print(ti.infer_type('123'))        # DataType.INTEGER
print(ti.infer_type('1.23'))       # DataType.FLOAT
print(ti.infer_type('true'))       # DataType.BOOLEAN
print(ti.infer_type('2023-01-01')) # DataType.DATE

# Type conversion
print(ti.convert_value('123'))        # 123 (int)
print(ti.convert_value('1.23'))       # 1.23 (float)
print(ti.convert_value('true'))       # True (bool)

Collection Analysis

# Analyze collections of values
values1 = ['1', '2', '3']
print(ti.profile_values(values1))  # DataType.INTEGER

values2 = ['1.1', '2.2', '3.3']
print(ti.profile_values(values2))  # DataType.FLOAT

values3 = ['1', '2.2', 'hello']
print(ti.profile_values(values3))  # DataType.MIXED

Supported Data Types

The library can infer the following data types:

  • INTEGER: Whole numbers ('123', '-456', '00123')
  • FLOAT: Decimal numbers ('1.23', '-4.56', '1.0')
  • BOOLEAN: True/false values ('true', 'false', 'True', 'False')
  • DATE: Date values in various formats ('2023-01-01', '01/01/2023', '20230101')
  • TIME: Time values ('14:30:00', '2:30 PM', '143000')
  • DATETIME: Combined date and time ('2023-01-01T12:00:00', '2023-01-01 12:00:00')
  • STRING: Text data that doesn't match other patterns
  • EMPTY: Empty strings or whitespace-only strings
  • NONE: Null values ('none', 'null', None)
  • MIXED: Collections containing multiple data types

Advanced Usage

Handling Edge Cases

# Leading zeros are handled correctly
print(ti.infer_type('00123'))  # DataType.INTEGER

# Invalid dates fall back to string
print(ti.infer_type('2023-13-01'))  # May be interpreted as date in some formats

# Mixed collections
mixed_values = ['123', 'abc', '2023-01-01']
print(ti.profile_values(mixed_values))  # DataType.MIXED

Performance Considerations

For large datasets (>10,000 items), the library automatically enables incremental type checking for better performance:

large_dataset = [str(i) for i in range(50000)]
result = ti.profile_values(large_dataset)  # Uses optimized incremental processing

API Reference

TypeInference Class

Methods

  • infer_type(value: str) -> DataType: Infer type of a single value
  • convert_value(value: Any) -> Any: Convert value to its inferred type
  • profile_values(values: Iterable[Any]) -> DataType: Analyze a collection of values

String Class

Low-level string processing utilities:

  • is_int_like(), is_float_like(), is_bool_like(), etc.
  • to_int(), to_float(), to_bool(), etc.
  • infer_type() - direct type inference

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Author

Jim Schilling (c) 2025

Project details


Download files

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

Source Distribution

splurge_typer-2025.0.0.tar.gz (15.0 kB view details)

Uploaded Source

Built Distribution

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

splurge_typer-2025.0.0-py3-none-any.whl (14.8 kB view details)

Uploaded Python 3

File details

Details for the file splurge_typer-2025.0.0.tar.gz.

File metadata

  • Download URL: splurge_typer-2025.0.0.tar.gz
  • Upload date:
  • Size: 15.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for splurge_typer-2025.0.0.tar.gz
Algorithm Hash digest
SHA256 d618cca2c105e6bdc5264c23049978f4b75821ef00df57e8e5703af0df19bb3f
MD5 8fde4e7763680a2328d509062e77706a
BLAKE2b-256 7c23c17d17f7ecdef8bcf56245f956c85a9b8d3668dfa62780c714fc52023194

See more details on using hashes here.

File details

Details for the file splurge_typer-2025.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for splurge_typer-2025.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d29973a5864d2e922844f290bac010b527ca7d51da41e9428f03e3af424fa572
MD5 036d68570ce446ac7a97d8db6895f994
BLAKE2b-256 47b1240b6c49d5409d11b452e0c9e7e537b20bb92360c68939f0ef5ee937878a

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