dragon-ml-toolbox 10.11.0__py3-none-any.whl → 10.11.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of dragon-ml-toolbox might be problematic. Click here for more details.
- {dragon_ml_toolbox-10.11.0.dist-info → dragon_ml_toolbox-10.11.2.dist-info}/METADATA +1 -1
- {dragon_ml_toolbox-10.11.0.dist-info → dragon_ml_toolbox-10.11.2.dist-info}/RECORD +8 -8
- ml_tools/path_manager.py +18 -11
- ml_tools/utilities.py +39 -5
- {dragon_ml_toolbox-10.11.0.dist-info → dragon_ml_toolbox-10.11.2.dist-info}/WHEEL +0 -0
- {dragon_ml_toolbox-10.11.0.dist-info → dragon_ml_toolbox-10.11.2.dist-info}/licenses/LICENSE +0 -0
- {dragon_ml_toolbox-10.11.0.dist-info → dragon_ml_toolbox-10.11.2.dist-info}/licenses/LICENSE-THIRD-PARTY.md +0 -0
- {dragon_ml_toolbox-10.11.0.dist-info → dragon_ml_toolbox-10.11.2.dist-info}/top_level.txt +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
dragon_ml_toolbox-10.11.
|
|
2
|
-
dragon_ml_toolbox-10.11.
|
|
1
|
+
dragon_ml_toolbox-10.11.2.dist-info/licenses/LICENSE,sha256=2uUFNy7D0TLgHim1K5s3DIJ4q_KvxEXVilnU20cWliY,1066
|
|
2
|
+
dragon_ml_toolbox-10.11.2.dist-info/licenses/LICENSE-THIRD-PARTY.md,sha256=lY4_rJPnLnMu7YBQaY-_iz1JRDcLdQzNCyeLAF1glJY,1837
|
|
3
3
|
ml_tools/ETL_cleaning.py,sha256=lSP5q6-ukGhJBPV8dlsqJvPXAzj4du_0J-SbtEd0Pjg,19292
|
|
4
4
|
ml_tools/ETL_engineering.py,sha256=a6KCWH6kRatZtjaFEF_o917ApPMK5_vRD-BjfCDAl-E,49400
|
|
5
5
|
ml_tools/GUI_tools.py,sha256=kEQWg-bog3pB5tI22gMGKWaCGHnz9TB2Lvvfhf5F2CI,45412
|
|
@@ -28,9 +28,9 @@ ml_tools/ensemble_learning.py,sha256=3s0kH4i_naj0IVl_T4knst-Hwg4TScWjEdsXX5KAi7I
|
|
|
28
28
|
ml_tools/handle_excel.py,sha256=He4UT15sCGhaG-JKfs7uYVAubxWjrqgJ6U7OhMR2fuE,14005
|
|
29
29
|
ml_tools/keys.py,sha256=FDpbS3Jb0pjrVvvp2_8nZi919mbob_-xwuy5OOtKM_A,1848
|
|
30
30
|
ml_tools/optimization_tools.py,sha256=P3I6lIpvZ8Xf2kX5FvvBKBmrK2pB6idBpkTzfUJxTeE,5073
|
|
31
|
-
ml_tools/path_manager.py,sha256=
|
|
32
|
-
ml_tools/utilities.py,sha256=
|
|
33
|
-
dragon_ml_toolbox-10.11.
|
|
34
|
-
dragon_ml_toolbox-10.11.
|
|
35
|
-
dragon_ml_toolbox-10.11.
|
|
36
|
-
dragon_ml_toolbox-10.11.
|
|
31
|
+
ml_tools/path_manager.py,sha256=ke0MYOhYheRPX599GUbrvRsYHn2JKUmMDldS5LP6LQA,18431
|
|
32
|
+
ml_tools/utilities.py,sha256=uheMUjQJ1zI69gASsE-mCq4KlRPVGgrgqson02rGNYM,30755
|
|
33
|
+
dragon_ml_toolbox-10.11.2.dist-info/METADATA,sha256=bBK3PyfNJ-e6nvmGlyHg3HvDLSnmDsKHbo7KwovMWck,6969
|
|
34
|
+
dragon_ml_toolbox-10.11.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
35
|
+
dragon_ml_toolbox-10.11.2.dist-info/top_level.txt,sha256=wm-oxax3ciyez6VoO4zsFd-gSok2VipYXnbg3TH9PtU,9
|
|
36
|
+
dragon_ml_toolbox-10.11.2.dist-info/RECORD,,
|
ml_tools/path_manager.py
CHANGED
|
@@ -248,26 +248,33 @@ class PathManager:
|
|
|
248
248
|
_LOGGER.error(f"'{type(self).__name__}' object has no attribute or path key '{sanitized_name}'")
|
|
249
249
|
raise AttributeError()
|
|
250
250
|
|
|
251
|
-
def __setattr__(self, name: str, value: Union[str, Path]):
|
|
251
|
+
def __setattr__(self, name: str, value: Union[str, Path, bool, dict, str, int, tuple]):
|
|
252
252
|
"""Allows attribute-style setting of paths, e.g., PM.data = 'path/to/data'."""
|
|
253
|
-
# Check for internal attributes
|
|
253
|
+
# Check for internal attributes, which are set directly on the object.
|
|
254
254
|
if name.startswith('_'):
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
255
|
+
# This check prevents setting new private attributes after __init__ is done.
|
|
256
|
+
is_initialized = self.__dict__.get('_initialized', False)
|
|
257
|
+
if is_initialized:
|
|
258
|
+
_LOGGER.error(f"Cannot set private attribute '{name}' after initialization.")
|
|
259
|
+
raise AttributeError()
|
|
260
|
+
super().__setattr__(name, value)
|
|
261
261
|
return
|
|
262
262
|
|
|
263
|
-
#
|
|
263
|
+
# Sanitize the key for the public path.
|
|
264
264
|
sanitized_name = self._sanitize_key(name)
|
|
265
265
|
self._check_underscore_key(sanitized_name)
|
|
266
|
-
|
|
266
|
+
|
|
267
|
+
# Prevent overwriting existing methods (e.g., PM.status = 'foo').
|
|
268
|
+
# This check looks at the class, not the instance therefore won't trigger __getattr__.
|
|
269
|
+
if hasattr(self.__class__, sanitized_name):
|
|
267
270
|
_LOGGER.error(f"Cannot overwrite existing attribute or method '{sanitized_name}' ({name}).")
|
|
268
271
|
raise AttributeError()
|
|
272
|
+
|
|
273
|
+
if not isinstance(value, (str, Path)):
|
|
274
|
+
_LOGGER.error(f"Cannot assign type '{type(value).__name__}' to a path. Must be str or Path.")
|
|
275
|
+
raise TypeError
|
|
269
276
|
|
|
270
|
-
# If all checks pass, treat it as a public path.
|
|
277
|
+
# If all checks pass, treat it as a public path and store it in the _paths dictionary.
|
|
271
278
|
self._paths[sanitized_name] = Path(value)
|
|
272
279
|
|
|
273
280
|
|
ml_tools/utilities.py
CHANGED
|
@@ -3,7 +3,7 @@ import numpy as np
|
|
|
3
3
|
import pandas as pd
|
|
4
4
|
import polars as pl
|
|
5
5
|
from pathlib import Path
|
|
6
|
-
from typing import Literal, Union, Sequence, Optional, Any, Iterator, Tuple, overload
|
|
6
|
+
from typing import Literal, Union, Sequence, Optional, Any, Iterator, Tuple, overload, TypeVar, get_origin, Type
|
|
7
7
|
import joblib
|
|
8
8
|
from joblib.externals.loky.process_executor import TerminatedWorkerError
|
|
9
9
|
from .path_manager import sanitize_filename, make_fullpath, list_csv_paths, list_files_by_extension, list_subdirectories
|
|
@@ -444,16 +444,32 @@ def serialize_object(obj: Any, save_dir: Union[str,Path], filename: str, verbose
|
|
|
444
444
|
_LOGGER.info(f"Object of type '{type(obj)}' saved to '{full_path}'")
|
|
445
445
|
return None
|
|
446
446
|
|
|
447
|
-
|
|
448
|
-
|
|
447
|
+
# Define a TypeVar to link the expected type to the return type of deserialization
|
|
448
|
+
T = TypeVar('T')
|
|
449
|
+
|
|
450
|
+
def deserialize_object(
|
|
451
|
+
filepath: Union[str, Path],
|
|
452
|
+
expected_type: Optional[Type[T]] = None,
|
|
453
|
+
verbose: bool = True,
|
|
454
|
+
raise_on_error: bool = True
|
|
455
|
+
) -> Optional[T]:
|
|
449
456
|
"""
|
|
450
457
|
Loads a serialized object from a .joblib file.
|
|
451
458
|
|
|
452
459
|
Parameters:
|
|
453
460
|
filepath (str | Path): Full path to the serialized .joblib file.
|
|
461
|
+
expected_type (Type[T] | None): The expected type of the object.
|
|
462
|
+
If provided, the function raises a TypeError if the loaded object
|
|
463
|
+
is not an instance of this type. It correctly handles generics
|
|
464
|
+
like `list[str]` by checking the base type (e.g., `list`).
|
|
465
|
+
Defaults to None, which skips the type check.
|
|
466
|
+
verbose (bool): If True, logs success messages.
|
|
467
|
+
raise_on_error (bool): If True, raises exceptions on errors. If False, returns None instead.
|
|
454
468
|
|
|
455
469
|
Returns:
|
|
456
|
-
(Any | None): The deserialized Python object,
|
|
470
|
+
(Any | None): The deserialized Python object, which will match the
|
|
471
|
+
`expected_type` if provided. Returns None if an error
|
|
472
|
+
occurs and `raise_on_error` is False.
|
|
457
473
|
"""
|
|
458
474
|
true_filepath = make_fullpath(filepath)
|
|
459
475
|
|
|
@@ -465,8 +481,26 @@ def deserialize_object(filepath: Union[str,Path], verbose: bool=True, raise_on_e
|
|
|
465
481
|
raise e
|
|
466
482
|
return None
|
|
467
483
|
else:
|
|
484
|
+
# --- Type Validation Step ---
|
|
485
|
+
if expected_type:
|
|
486
|
+
# get_origin handles generics (e.g., list[str] -> list)
|
|
487
|
+
# If it's not a generic, get_origin returns None, so we use the type itself.
|
|
488
|
+
type_to_check = get_origin(expected_type) or expected_type
|
|
489
|
+
|
|
490
|
+
# Can't do an isinstance check on 'Any', skip it.
|
|
491
|
+
if type_to_check is not Any and not isinstance(obj, type_to_check):
|
|
492
|
+
error_msg = (
|
|
493
|
+
f"Type mismatch: Expected an instance of '{expected_type}', "
|
|
494
|
+
f"but found '{type(obj)}' in '{true_filepath}'."
|
|
495
|
+
)
|
|
496
|
+
_LOGGER.error(error_msg)
|
|
497
|
+
if raise_on_error:
|
|
498
|
+
raise TypeError()
|
|
499
|
+
return None
|
|
500
|
+
|
|
468
501
|
if verbose:
|
|
469
|
-
_LOGGER.info(f"Loaded object of type '{type(obj)}'.")
|
|
502
|
+
_LOGGER.info(f"Loaded object of type '{type(obj)}' from '{true_filepath}'.")
|
|
503
|
+
|
|
470
504
|
return obj
|
|
471
505
|
|
|
472
506
|
|
|
File without changes
|
{dragon_ml_toolbox-10.11.0.dist-info → dragon_ml_toolbox-10.11.2.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|