PickleFormatter¶
- class lsst.daf.butler.formatters.pickle.PickleFormatter(file_descriptor: FileDescriptor, *, ref: DatasetRef, write_parameters: Mapping[str, Any] | None = None, write_recipes: Mapping[str, Any] | None = None, **kwargs: Any)¶
Bases:
TypelessFormatter
Interface for reading and writing Python objects to and from pickle files.
Attributes Summary
Declare whether
read_from_uri
is available to this formatter.Default extension to use when writing a file.
Set of read parameters not understood by this
Formatter
.Methods Summary
read_from_uri
(uri[, component, expected_size])Read a dataset from a URI that can be local or remote.
to_bytes
(in_memory_dataset)Serialize the in-memory dataset to bytes.
Attributes Documentation
- can_read_from_uri: ClassVar[bool] = True¶
Declare whether
read_from_uri
is available to this formatter.
- default_extension: ClassVar[str | None] = '.pickle'¶
Default extension to use when writing a file.
Can be
None
if the extension is determined dynamically. Use theget_write_extension
method to get the actual extension to use.
- unsupported_parameters: ClassVar[Set[str] | None] = None¶
Set of read parameters not understood by this
Formatter
. An empty set means all parameters are supported.None
indicates that no parameters are supported. These parameters should match those defined in the storage class definition. (frozenset
).
Methods Documentation
- read_from_uri(uri: ResourcePath, component: str | None = None, expected_size: int = -1) Any ¶
Read a dataset from a URI that can be local or remote.
- Parameters:
- uri
lsst.resources.ResourcePath
URI to use to read the dataset. This URI can be local or remote and can refer to the actual resource or to a locally cached file.
- component
str
orNone
, optional The component to be read from the dataset.
- expected_size
int
, optional If known, the expected size of the resource to read. This can be
-1
indicates the file size is not known.
- uri
- Returns:
- in_memory_dataset
object
orNotImplemented
The Python object read from the resource or
NotImplemented
.
- in_memory_dataset
- Raises:
- FormatterNotImplementedError
Raised if there is no support for direct reads from a, possibly, remote URI.
Notes
This method is only called if the class property
can_read_from_uri
is set toTrue
.It is possible that a cached local file will be given to this method even if it was originally a remote URI. This can happen if the original write resulted in the file being added to the local cache.
If the full file is being read this file will not be added to the local cache. Consider returning
NotImplemented
in this situation, for example if there are no parameters or component specified, and allowing the system to fall back to callingread_from_local_file
(which will populate the cache if configured to do so).
- to_bytes(in_memory_dataset: Any) bytes ¶
Serialize the in-memory dataset to bytes.
- Parameters:
- in_memory_dataset
object
The Python object to serialize.
- in_memory_dataset
- Returns:
- serialized_dataset
bytes
Bytes representing the serialized dataset.
- serialized_dataset
- Raises:
- FormatterNotImplementedError
Raised if the formatter has not implemented the method. This will not cause a problem if
write_local_file
has been implemented.