ray.data.preprocessors.LabelEncoder.deserialize#

static LabelEncoder.deserialize(serialized: str | bytes) Preprocessor#

Deserialize a preprocessor from serialized data.

⚠️ DO NOT OVERRIDE THIS METHOD IN SUBCLASSES ⚠️

This method is marked as @final in the concrete implementation and handles the complete deserialization orchestration. Subclasses should implement the abstract methods instead: _set_serializable_fields() and _set_stats().

Deserialization Process:

  1. Detects format from magic bytes in serialized data

  2. Delegates to SerializationHandlerFactory for format-specific parsing

  3. Extracts metadata (type, version, fields, stats)

  4. Looks up preprocessor class from registry

  5. Creates new instance and restores state via abstract methods

  6. Returns fully reconstructed preprocessor instance

Format Detection:

The method automatically detects the serialization format: - CPKL: → CloudPickle format - Base64 string → Legacy Pickle format

Error Handling:

Provides comprehensive error handling for: - Unknown serialization formats - Corrupted or invalid data - Missing preprocessor types - Version compatibility issues

Parameters:

serialized – Serialized preprocessor data (bytes or str)

Returns:

Reconstructed preprocessor instance

Raises:
  • ValueError – If the serialized data is corrupted or format is unrecognized

  • UnknownPreprocessorError – If the preprocessor type is not registered

DeveloperAPI: This API may change across minor Ray releases.