Skip to content

numpy

Classes:

  • NpyDumpArgs

    Arguments for dumping a NumPy array.

  • NpyLoadArgs

    Arguments for loading a NumPy array.

  • NpySerializer

    Serializer for NumPy arrays using the native .npy format.

npy_serializer module-attribute

npy_serializer = NpySerializer()

NpySerializer with default settings.

NpyDumpArgs

Bases: TypedDict

Arguments for dumping a NumPy array.

NpyLoadArgs

Bases: TypedDict

Arguments for loading a NumPy array.

Attributes:

  • mmap_mode (Literal['r+', 'r', 'w+', 'c'] | None) –

    If not None, then memory-map the file, using the given mode.

mmap_mode instance-attribute

mmap_mode: Literal['r+', 'r', 'w+', 'c'] | None

If not None, then memory-map the file, using the given mode.

See numpy.memmap for a detailed description of the modes. A memory-mapped array is kept on disk. However, it can be accessed and sliced like any ndarray. Memory mapping is especially useful for accessing small fragments of large files without reading the entire file into memory.

NpySerializer

NpySerializer(
    *,
    dump_args: NpyDumpArgs | None = None,
    load_args: NpyLoadArgs | None = None
)

Bases: Serializer[ndarray]

Serializer for NumPy arrays using the native .npy format.

This serializer leverages NumPy's built-in numpy.save and numpy.load functions to efficiently serialize and deserialize numpy.ndarray objects.

Parameters:

  • dump_args

    (NpyDumpArgs | None, default: None ) –

    Optional arguments passed to numpy.save.

  • load_args

    (NpyLoadArgs | None, default: None ) –

    Optional arguments passed to numpy.load.

Methods:

Attributes:

content_types class-attribute instance-attribute

content_types: tuple[str, ...] = ()

The content types that the serializer uses.

Used to get serializers by content type in the registry.

deserialize_config

deserialize_config(config: str) -> C

Deserialize the configuration from a JSON string.

deserialize_data

deserialize_data(content: SerializedData) -> ndarray

Deserialize the given DataFrame.

serialize_config

serialize_config(config: C) -> str

Serialize the configuration to a JSON string.

serialize_data

serialize_data(value: ndarray) -> SerializedData

Serialize the given DataFrame.