mutcleaner.utils.type_converter#
Type conversion utilities for pandas DataFrames.
This module provides flexible and efficient data type conversion capabilities with support for pandas, numpy, and Python built-in types.
Functions
|
Convert data types for specified columns with enhanced type support. |
|
Batch conversion version for large datasets. |
|
Intelligent boolean conversion handling various boolean representations. |
|
Get appropriate conversion function for target type. |
|
Normalize type conversion mapping to standardized format. |
- mutcleaner.utils.type_converter.convert_data_types(dataset, type_conversions, handle_errors='coerce', optimize_memory=True)[source]#
Convert data types for specified columns with enhanced type support.
- Parameters:
dataset (
DataFrame) – Input dataset with columns to be convertedtype_conversions (
Dict[str,Union[str,Type,dtype]]) – Type conversion mapping in format {column_name: target_type} Supported formats: - String types: ‘float’, ‘int’, ‘str’, ‘category’, ‘bool’, ‘datetime’ - Numpy types: np.float32, np.float64, np.int32, np.int64, etc. - Pandas types: ‘Int64’, ‘Float64’, ‘string’, ‘boolean’ - Python types: float, int, str, boolhandle_errors (
str) – Error handling strategy: ‘raise’, ‘coerce’, or ‘ignore’optimize_memory (
bool) – Whether to automatically optimize memory usage
- Return type:
DataFrame- Returns:
Dataset with converted data types
- mutcleaner.utils.type_converter.convert_data_types_batch(dataset, type_conversions, handle_errors='coerce', optimize_memory=True, chunk_size=10000)[source]#
Batch conversion version for large datasets.
- Parameters:
dataset (
DataFrame) – Input datasettype_conversions (
Dict[str,Union[str,Type,dtype]]) – Type conversion mappinghandle_errors (
str) – Error handling strategyoptimize_memory (
bool) – Whether to optimize memory usagechunk_size (
int) – Chunk size for processing large datasets
- Return type:
DataFrame- Returns:
Dataset with converted data types
- mutcleaner.utils.type_converter.convert_to_boolean(series, errors)[source]#
Intelligent boolean conversion handling various boolean representations.
- Parameters:
series (
Series) – Input series to converterrors (
str) – Error handling strategy
- Return type:
Series- Returns:
Boolean series
- mutcleaner.utils.type_converter.get_conversion_function(target_type, optimize_memory)[source]#
Get appropriate conversion function for target type.
- Parameters:
target_type (
Union[str,Type,dtype]) – Target data typeoptimize_memory (
bool) – Whether to use memory-optimized types
- Return type:
Tuple[str,Callable]- Returns:
Type name and conversion function