Python tools for data type handling and validation
Project description
splurge-tools
A Python package providing tools for data type handling, validation, and text processing.
Description
splurge-tools is a collection of Python utilities focused on:
- Data type handling and validation
- Text file processing and manipulation
- String tokenization and parsing
- Text case transformations
- Delimited separated value parsing
- Tabular data model class
- Typed tabular data model class
- Data validator class
- Random data class
- Data transformation class
- Text normalizer class
- Python 3.10+ compatibility
Installation
pip install splurge-tools
Features
type_helper.py: Comprehensive type validation and conversion utilitiestext_file_helper.py: Text file processing and manipulation toolsstring_tokenizer.py: String parsing and tokenization utilitiescase_helper.py: Text case transformation utilitiesdsv_helper.py: Delimited separated value utilitiestabular_data_model.py: Data model for tabular datasetstyped_tabular_data_model.py: Type data model based on tabular data modeldata_validator.py: Data validator classrandom_helper.py: Random data class and methods for generating datadata_transformer.py: Data transformation utility classtext_normalizer.py: Text normalization utility class
Development
Requirements
- Python 3.10 or higher
- setuptools
- wheel
Setup
- Clone the repository:
git clone https://github.com/jim-schilling/splurge-tools.git
cd splurge-tools
- Create and activate a virtual environment:
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
- Install development dependencies:
pip install -e ".[dev]"
Testing
Run tests using pytest:
python -m pytest tests/
Code Quality
The project uses several tools to maintain code quality:
- Black: Code formatting
- isort: Import sorting
- flake8: Linting
- mypy: Type checking
- pytest: Testing with coverage
Run all quality checks:
black .
isort .
flake8 splurge_tools/ tests/ --max-line-length=120
mypy splurge_tools/
python -m pytest tests/ --cov=splurge_tools
Build
Build distribution:
python -m build
Changelog
[0.2.5] - 2025-07-10
Changed
- Test Organization: Reorganized test files to improve clarity and maintainability by separating core functionality tests from complex/integration tests. Split the following test files:
test_dsv_helper.py: Kept core parsing tests; moved file I/O and streaming tests totest_dsv_helper_file_stream.pytest_streaming_tabular_data_model.py: Kept core streaming model tests; moved complex scenarios and edge cases totest_streaming_tabular_data_model_complex.pytest_text_file_helper.py: Kept core text file operations; moved streaming tests totest_text_file_helper_streaming.py
- Import Cleanup: Removed unused import statements from all test files to improve code quality and maintainability:
- Removed unused
DataTypeimport fromtest_dsv_helper.py - Removed unused
Iteratorimports from streaming tabular data model test files
- Removed unused
- String Class Refactoring: Migrated method-level constants to class-level constants in
type_helper.pyString class for improved performance and maintainability:- Moved date/time/datetime pattern lists to class-level constants (
_DATE_PATTERNS,_TIME_PATTERNS,_DATETIME_PATTERNS) - Moved regex patterns to class-level constants (
_FLOAT_REGEX,_INTEGER_REGEX,_DATE_YYYY_MM_DD_REGEX, etc.) - This eliminates repeated pattern compilation on each method call and improves code organization
- Moved date/time/datetime pattern lists to class-level constants (
Fixed
- Test Expectations: Fixed test failures related to incorrect expectations for
profile_columnsmethod keys (datatypeinstead oftypeand nocountkey) and adjusted error message regex in streaming tabular data model tests. - String Class Regex Patterns: Fixed regex patterns in
type_helper.pyString class for datetime parsing. Updated_DATETIME_YYYY_MM_DD_REGEXand_DATETIME_MM_DD_YYYY_REGEXpatterns to properly handle microseconds with[.]?\d+instead of the incorrect[.]?\d{5}pattern.
Testing
- Maintained Coverage: All 167 tests continue to pass with 96% code coverage after reorganization and cleanup.
- Improved Maintainability: Test organization now provides clearer separation between core functionality and complex scenarios, enabling selective test execution and better code organization.
[0.2.4] - 2025-07-05
Fixed
- profile_values Edge Case: Fixed edge case in
profile_valuesfunction where collections of all-digit strings that could be interpreted as different types (DATE, TIME, DATETIME, INTEGER) were being classified as MIXED instead of INTEGER. The function now prioritizes INTEGER type when all values are all-digit strings (with optional +/- signs) and there's a mix of DATE, TIME, DATETIME, and INTEGER interpretations. - profile_values Iterator Safety: Fixed issue where
profile_valuesfunction would fail when given a non-reusable iterator (e.g., generator). The function now uses a 2-pass approach that always uses a list for the special case logic is needed, ensuring both correctness with generators.
[0.2.3] - 2025-07-05
Changed
- API Simplification: Removed the
multi_row_headersparameter fromTabularDataModel,StreamingTabularDataModel,TypedTabularDataModel, andDsvHelper.profile_columns. Multi-row header merging is now controlled solely by theheader_rowsparameter, which specifies how many rows to merge for column names. This change simplifies the API and eliminates redundant parameters. - StreamingTabularDataModel API Refinement: Streamlined the
StreamingTabularDataModelAPI to focus on streaming functionality by removing random access methods (row(),row_as_list(),row_as_tuple(),cell_value()) and column analysis methods (column_values(),column_type()). This creates a cleaner, more consistent streaming paradigm. - Tests and Examples Updated: All tests and example scripts have been updated to use only the
header_rowsparameter for multi-row header merging. Any usage ofmulti_row_headershas been removed. - StringTokenizer Tests Refactored: Consolidated and removed redundant tests in
test_string_tokenizer.pyfor improved maintainability and clarity. Test coverage and edge case handling remain comprehensive.
Added
- StreamingTabularDataModel: New streaming tabular data model for large datasets that don't fit in memory. Works with streams from
DsvHelper.parse_streamto process data without loading the entire dataset into memory. Features include:- Memory-efficient streaming processing with configurable chunk sizes (minimum 100 rows)
- Support for multi-row headers with automatic merging
- Multiple iteration methods (as lists, dictionaries, tuples)
- Empty row skipping and uneven row handling
- Comprehensive error handling and validation
- Dynamic column expansion during iteration
- Row padding for uneven data
- Comprehensive Test Coverage: Added extensive test suite for
StreamingTabularDataModelwith 26 test methods covering:- Basic functionality with and without headers
- Multi-row header processing
- Buffer operations and memory management
- Iteration methods (direct, dict, tuple)
- Error handling for invalid parameters and columns
- Edge cases (empty files, large datasets, uneven rows, empty headers)
- Header validation and initialization
- Chunk processing and buffer size limits
- Dynamic column expansion and row padding
- Streaming Data Example: Added comprehensive example demonstrating
StreamingTabularDataModelusage, including memory usage comparison with traditional loading methods.
Fixed
- Header Processing: Fixed header processing logic in all data models (
StreamingTabularDataModel,TabularDataModel,TypedTabularDataModel) to properly handle empty headers by filling them withcolumn_<index>names. Headers like"Name,,City"now correctly become["Name", "column_1", "City"]. - DSV Parsing: Fixed
StringTokenizer.parseto preserve empty fields instead of filtering them out. This ensures that"Name,,City"is parsed as["Name", "", "City"]instead of["Name", "City"], maintaining data integrity. - Row Padding and Dynamic Column Expansion: Fixed row padding logic in
StreamingTabularDataModelto properly handle uneven rows and dynamically expand columns during iteration. - File Handling: Fixed file permission errors in tests by ensuring proper cleanup of temporary files and stream exhaustion.
Performance
- Memory Efficiency:
StreamingTabularDataModelprovides significant memory savings for large datasets by processing data in configurable chunks rather than loading entire files into memory. - Streaming Processing: Enables processing of datasets larger than available RAM through efficient streaming and buffer management.
Testing
- 94% Test Coverage: Achieved 94% test coverage for
StreamingTabularDataModelwith comprehensive edge case testing. - Error Condition Testing: Added thorough testing of error conditions including invalid parameters and missing columns.
- Integration Testing: Tests cover integration with
DsvHelper.parse_streamand various data formats. - StringTokenizer Tests Updated: Updated
StringTokenizertests to reflect the new behavior of preserving empty fields.
[0.2.2] - 2025-07-04
Added
- TextFileHelper.load_as_stream: Added new method for memory-efficient streaming of large text files with configurable chunk sizes. Supports header/footer row skipping and uses optimized deque-based sliding window for footer handling.
- TextFileHelper.preview skip_header_rows parameter: Added
skip_header_rowsparameter to thepreview()method, allowing users to skip header rows when previewing file contents.
Performance
- TextFileHelper Footer Buffer Optimization: Replaced list-based footer buffer with
collections.dequeinload_as_stream()method, improving performance from O(n) to O(1) for footer row operations.
Fixed
- TabularDataModel No-Header Scenarios: Fixed issue where column names were empty when
header_rows=0. Column names are now properly generated as["column_0", "column_1", "column_2"]when no headers are provided. - TabularDataModel Row Access: Fixed
IndexErrorin therow()method when accessing uneven data rows. Added proper padding logic to ensure row data has enough columns before access. - TabularDataModel Data Normalization: Improved consistency between column count and column names by ensuring column names always match the actual column count, regardless of header configuration.
[0.2.1] - 2025-07-03
Added
- DsvHelper.profile_columns: Added
DsvHelper.profile_columns, a new method that generates a simple data profile from parsed DSV data, inferring column names and datatypes. - Test Coverage: Added comprehensive test cases for
DsvHelper.profile_columnsand improved validation of DSV parsing logic, including edge cases for all supported datatypes.
[0.2.0] - 2025-07-02
Breaking Changes
- Method Signature Standardization: All method signatures across the codebase have been updated to require default parameters to be named (e.g.,
def myfunc(value: str, *, trim: bool = True)). This enforces keyword-only arguments for all default values, improving clarity and consistency. This is a breaking change and may require updates to any code that calls these methods positionally for defaulted parameters. - All method signatures now use explicit type annotations and follow PEP8 and project-specific conventions for parameter ordering and naming.
- Some methods may have reordered parameters or stricter type requirements as part of this standardization.
Fixed
- Resolved Regex Pattern Bug: Fixed regex pattern bug - ?? should have been ? in String class in type_helper.py.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Author
Jim Schilling
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file splurge_tools-0.2.5.tar.gz.
File metadata
- Download URL: splurge_tools-0.2.5.tar.gz
- Upload date:
- Size: 55.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d81a33a653bb56a6e9e6e834c899d4a92e68093827926747e3325aeef2a91061
|
|
| MD5 |
890d4bf9493897657894adf576b30cd9
|
|
| BLAKE2b-256 |
dc51e5844c2a4374cd035cd33f13313e3cc175f8ca3b61b1a7bc87e54bf0e87e
|
File details
Details for the file splurge_tools-0.2.5-py3-none-any.whl.
File metadata
- Download URL: splurge_tools-0.2.5-py3-none-any.whl
- Upload date:
- Size: 35.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
74a818487713fd3ad59eb49a7c63d4c39b72034d6cdd60032be3cc40207e7104
|
|
| MD5 |
be0c2cc89c5f998cd95063d1fcfd7703
|
|
| BLAKE2b-256 |
5dc887d83c6303f26f13d329e40f47266caa8259a6dfbe48d5021673ad6c5252
|