StorageClass

class lsst.daf.butler.StorageClass(name: str | None = None, pytype: type | str | None = None, components: dict[str, lsst.daf.butler._storage_class.StorageClass] | None = None, derivedComponents: dict[str, lsst.daf.butler._storage_class.StorageClass] | None = None, parameters: Sequence[str] | Set[str] | None = None, delegate: str | None = None, converters: dict[str, str] | None = None)

Bases: object

Class describing how a label maps to a particular Python type.

Parameters:
namestr

Name to use for this class.

pytypetype or str

Python type (or name of type) to associate with the StorageClass.

componentsdict, optional

dict mapping name of a component to another StorageClass.

derivedComponentsdict, optional

dict mapping name of a derived component to another StorageClass.

parametersSequence or Set

Parameters understood by this StorageClass that can control reading of data from datastores.

delegatestr, optional

Fully qualified name of class supporting assembly and disassembly of a pytype instance.

convertersdict [str, str], optional

Mapping of python type to function that can be called to convert that python type to the valid type of this storage class.

Attributes Summary

components

Return the components associated with this StorageClass.

converters

Return the type converters supported by this StorageClass.

delegateClass

Class to use to delegate type-specific actions.

derivedComponents

Return derived components associated with StorageClass.

parameters

Return set of names of supported parameters.

pytype

Return Python type associated with this StorageClass.

Methods Summary

allComponents()

Return all defined components.

can_convert(other)

Return True if this storage class can convert python types in the other storage class.

coerce_type(incorrect)

Coerce the supplied incorrect instance to the python type associated with this StorageClass.

delegate()

Return an instance of a storage class delegate.

filterParameters(parameters[, subset])

Filter out parameters that are not known to this StorageClass.

isComposite()

Return Boolean indicating whether this is a composite or not.

is_type(other[, compare_types])

Return Boolean indicating whether the supplied type matches the type in this StorageClass.

knownParameters()

Return set of all parameters known to this StorageClass.

validateInstance(instance)

Check that the supplied Python object has the expected Python type.

validateParameters([parameters])

Check that the parameters are known to this StorageClass.

Attributes Documentation

components

Return the components associated with this StorageClass.

converters

Return the type converters supported by this StorageClass.

delegateClass

Class to use to delegate type-specific actions.

derivedComponents

Return derived components associated with StorageClass.

parameters

Return set of names of supported parameters.

pytype

Return Python type associated with this StorageClass.

Methods Documentation

allComponents() Mapping[str, StorageClass]

Return all defined components.

This mapping includes all the derived and read/write components for the corresponding storage class.

Returns:
compdict of [str, StorageClass]

The component name to storage class mapping.

can_convert(other: StorageClass) bool

Return True if this storage class can convert python types in the other storage class.

Parameters:
otherStorageClass

The storage class to check.

Returns:
canbool

True if this storage class has a registered converter for the python type associated with the other storage class. That converter will convert the other python type to the one associated with this storage class.

coerce_type(incorrect: Any) Any

Coerce the supplied incorrect instance to the python type associated with this StorageClass.

Parameters:
incorrectobject

An object that might be the incorrect type.

Returns:
correctobject

An object that matches the python type of this StorageClass. Can be the same object as given. If None, None will be returned.

Raises:
TypeError

Raised if no conversion can be found.

delegate() StorageClassDelegate

Return an instance of a storage class delegate.

Returns:
delegateStorageClassDelegate

Instance of the delegate associated with this StorageClass. The delegate is constructed with this StorageClass.

Raises:
TypeError

This StorageClass has no associated delegate.

filterParameters(parameters: Mapping[str, Any] | None, subset: Collection | None = None) Mapping[str, Any]

Filter out parameters that are not known to this StorageClass.

Parameters:
parametersMapping, optional

Candidate parameters. Can be None if no parameters have been provided.

subsetCollection, optional

Subset of supported parameters that the caller is interested in using. The subset must be known to the StorageClass if specified. If None the supplied parameters will all be checked, else only the keys in this set will be checked.

Returns:
filteredMapping

Valid parameters. Empty dict if none are suitable.

Raises:
ValueError

Raised if the provided subset is not a subset of the supported parameters or if it is an empty set.

isComposite() bool

Return Boolean indicating whether this is a composite or not.

Returns:
isCompositebool

True if this StorageClass is a composite, False otherwise.

is_type(other: type, compare_types: bool = False) bool

Return Boolean indicating whether the supplied type matches the type in this StorageClass.

Parameters:
othertype

The type to be checked.

compare_typesbool, optional

If True the python type will be used in the comparison if the type names do not match. This may trigger an import of code and so can be slower.

Returns:
matchbool

True if the types are equal.

Notes

If this StorageClass has not yet imported the Python type the check is done against the full type name, this prevents an attempt to import the type when it will likely not match.

knownParameters() set[str]

Return set of all parameters known to this StorageClass.

The set includes parameters understood by components of a composite.

Returns:
knownset

All parameter keys of this StorageClass and the component storage classes.

validateInstance(instance: Any) bool

Check that the supplied Python object has the expected Python type.

Parameters:
instanceobject

Object to check.

Returns:
isOkbool

True if the supplied instance object can be handled by this StorageClass, False otherwise.

validateParameters(parameters: Collection | None = None) None

Check that the parameters are known to this StorageClass.

Does not check the values.

Parameters:
parametersCollection, optional

Collection containing the parameters. Can be dict-like or set-like. The parameter values are not checked. If no parameters are supplied, always returns without error.

Raises:
KeyError

Some parameters are not understood by this StorageClass.