nirs4all.data.loaders.numpy_loader module

NumPy file loader implementation.

This module provides the NumpyLoader class for loading NumPy array files, including .npy (single array) and .npz (multiple arrays) formats.

class nirs4all.data.loaders.numpy_loader.NumpyLoader[source]

Bases: FileLoader

Loader for NumPy array files.

Supports: - Single array files (.npy) - Multi-array archives (.npz)

Parameters:
  • allow_pickle – Whether to allow loading pickled objects (default: False). Setting this to True may pose a security risk with untrusted files.

  • key – For .npz files, the key of the array to load. If not specified, uses the first array.

  • header_unit – Unit for generated headers (‘cm-1’, ‘nm’, ‘index’, etc.)

Security Note:

NumPy’s allow_pickle=True can execute arbitrary code when loading untrusted files. Only enable this for files you trust completely.

load(path: Path, allow_pickle: bool = False, key: str | None = None, header_unit: str = 'index', data_type: str = 'x', **params: Any) LoaderResult[source]

Load data from a NumPy file.

Parameters:
  • path – Path to the NumPy file.

  • allow_pickle – Whether to allow loading pickled objects.

  • key – For .npz files, the key of the array to load.

  • header_unit – Unit type for generated headers.

  • data_type – Type of data (‘x’, ‘y’, or ‘metadata’).

  • **params – Additional parameters (ignored).

Returns:

LoaderResult with the loaded data as a DataFrame.

name: ClassVar[str] = 'NumPy Loader'
priority: ClassVar[int] = 40
supported_extensions: ClassVar[Tuple[str, ...]] = ('.npy', '.npz')
classmethod supports(path: Path) bool[source]

Check if this loader supports the given file.

nirs4all.data.loaders.numpy_loader.load_numpy(path, allow_pickle: bool = False, key: str | None = None, header_unit: str = 'index', **params)[source]

Load a NumPy file.

Convenience function for backward compatibility.

Parameters:
  • path – Path to the NumPy file.

  • allow_pickle – Whether to allow pickled objects.

  • key – For .npz files, the array key to load.

  • header_unit – Unit type for generated headers.

  • **params – Additional parameters.

Returns:

Tuple of (DataFrame, report, na_mask, headers, header_unit).