Coverage for python/lsst/daf/base/propertyContainer/propertyContainerContinued.py : 92%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# # LSST Data Management System # # Copyright 2008-2017 AURA/LSST. # # This product includes software developed by the # LSST Project (http://www.lsst.org/). # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the LSST License Statement and # the GNU General Public License along with this program. If not, # see <http://www.lsstcorp.org/LegalNotices/>. #
"""Get the state of a PropertySet in a form that can be pickled.
Parameters ---------- container : `PropertySet`\ The property container.
Returns ------- state : `list` The state, as a list of tuples, each of which contains the following 3 items: - name (a `str`): the name of the item - elementTypeName (a `str`): the suffix of a ``setX`` method name which is appropriate for the data type. For example integer data has ``elementTypeName="Int"` which corresponds to the ``setInt`` method. - value: the data for the item, in a form compatible with the set method named by ``elementTypeName`` """ _propertyContainerGet(container, name, returnStyle=ReturnStyle.AUTO)) for name in container.paramNames(False)]
"""Get the state of a PropertyList in a form that can be pickled.
Parameters ---------- container : `PropertyList` The property container.
Returns ------- state : `list` The state, as a list of tuples, each of which contains the following 4 items: - name (a `str`): the name of the item - elementTypeName (a `str`): the suffix of a ``setX`` method name which is appropriate for the data type. For example integer data has ``elementTypeName="Int"` which corresponds to the ``setInt`` method. - value: the data for the item, in a form compatible with the set method named by ``elementTypeName`` - comment (a `str`): the comment. This item is only present if ``container`` is a PropertyList. """ _propertyContainerGet(container, name, returnStyle=ReturnStyle.AUTO), container.getComment(name)) for name in container.getOrderedNames()]
"""Restore the state of a PropertySet, in place.
Parameters ---------- container : `PropertySet` The property container whose state is to be restored. It should be empty to start with and is updated in place. state : `list` The state, as returned by ``getPropertySetState`` """
"""Restore the state of a PropertyList, in place.
Parameters ---------- container : `PropertyList` The property container whose state is to be restored. It should be empty to start with and is updated in place. state : `list` The state, as returned by ``getPropertyListState`` """
"""Return name of the type of a particular element"""
"""Get a value of unknown type as a scalar or array
Parameters ---------- container : ``lsst.daf.base.PropertySet`` or ``lsst.daf.base.PropertyList`` Container from which to get the value name : ``str`` Name of item returnStyle : ``ReturnStyle`` Control whether numeric or string data is returned as an array or scalar (the other types, ``PropertyList``, ``PropertySet`` and ``PersistablePtr``, are always returned as a scalar): - ReturnStyle.ARRAY: return numeric or string data types as an array of values. - ReturnStyle.SCALAR: return numeric or string data types as a single value; if the item has multiple values then return the last value. - ReturnStyle.AUTO: (deprecated) return numeric or string data as a scalar if there is just one item, or as an array otherwise. """ raise ValueError("returnStyle {} must be a ReturnStyle".format(returnStyle))
try: return container.getAsPersistablePtr(name) except Exception: pass raise lsst.pex.exceptions.TypeError('Unknown PropertySet value type for ' + name)
"""Given an existing container and name, determine the type that should be used for the supplied value. The supplied value is assumed to be a scalar.
On Python 3 all ints are LongLong but we need to be able to store them in Int containers if that is what is being used (testing for truncation). Int is assumed to mean 32bit integer (2147483647 to -2147483648).
If there is no pre-existing value we have to decide what to do. For now we pick Int if the value is less than maxsize.
Returns None if the value supplied is a bool or not an integral value. """
# We do not want to convert bool to int so let the system work that # out itself
# nothing in the container so choose based on size. Safe option is to # always use LongLong else: useType = "LongLong" else: # Always use an Int even if we know it won't fit. The later # code will trigger OverflowError if appropriate. Setting the # type to LongLong here will trigger a TypeError instead so it's # best to trigger a predictable OverflowError. elif containerType == "LongLong": useType = "LongLong"
"""Set a single Python value of unknown type""" else:
# Allow for subclasses raise lsst.pex.exceptions.TypeError("Unknown value type for %s: %s" % (name, t))
"""Add a single Python value of unknown type""" else:
# Allow for subclasses raise lsst.pex.exceptions.TypeError("Unknown value type for %s: %s" % (name, t))
"""Make a ``PropertySet`` from the state returned by ``getstate``
Parameters ---------- state : `list` The data returned by ``getstate``. """
"""Make a ``PropertyList`` from the state returned by ``getstate``
Parameters ---------- state : `list` The data returned by ``getstate``. """
class PropertySet: # Mapping of type to method names; # int types are omitted due to use of _guessIntegerType float: "Double", str: "String", DateTime: "DateTime", PropertySet: "PropertySet", PropertyList: "PropertySet", }
# Map unicode to String, but this only works on Python 2 # so catch the error and do nothing on Python 3.
"""Return an item as a scalar or array
Return an array if the item is of numeric or string type and has more than one value, otherwise return a scalar.
.. deprecated:: 20180-06 `get` is superseded by `getArray` or `getScalar`
Parameters ---------- name : ``str`` Name of item
Raises ------ lsst.pex.exceptions.NotFoundError If the item does not exist. """
"""Return an item as an array if the item is numeric or string
If the item is a ``PropertySet``, ``PropertyList`` or ``lsst.daf.base.PersistablePtr`` then return the item as a scalar.
Parameters ---------- name : ``str`` Name of item
Raises ------ lsst.pex.exceptions.NotFoundError If the item does not exist. """
"""Return an item as a scalar
If the item has more than one value then the last value is returned
Parameters ---------- name : ``str`` Name of item
Raises ------ lsst.pex.exceptions.NotFoundError If the item does not exist. """
"""Set the value of an item
If the item already exists it is silently replaced; the types need not match.
Parameters ---------- name : ``str`` Name of item value : any supported type Value of item; may be a scalar or array """
"""Append one or more values to a given item, which need not exist
If the item exists then the new value(s) are appended; otherwise it is like calling `set`
Parameters ---------- name : ``str`` Name of item value : any supported type Value of item; may be a scalar or array
Notes ----- If `value` is an ``lsst.daf.base.PropertySet`` or ``lsst.daf.base.PropertyList`` then `value` replaces the existing value. Also the item is added as a live reference, so updating `value` will update this container and vice-versa.
Raises ------ lsst::pex::exceptions::TypeError If the type of `value` is incompatible with the existing value of the item. """
"""Returns a (possibly nested) dictionary with all properties. """
else:
# It would be a bit simpler to use __setstate__ and __getstate__. # However, implementing __setstate__ in Python causes segfaults # because pickle creates a new instance by calling # object.__new__(PropertyList, *args) which bypasses # the pybind11 memory allocation step.
class PropertyList: # Mapping of type to method names int: "Int", float: "Double", str: "String", DateTime: "DateTime", PropertySet: "PropertySet", PropertyList: "PropertySet", }
# Map unicode to String, but this only works on Python 2 # so catch the error and do nothing on Python 3.
"""Return an item as a scalar or array
Return an array if the item has more than one value, otherwise return a scalar.
.. deprecated:: 20180-06 `get` is superseded by `getArray` or `getScalar`
Parameters ---------- name : ``str`` Name of item
Raises ------ lsst.pex.exceptions.NotFoundError If the item does not exist. """
"""Return an item as an array
Parameters ---------- name : ``str`` Name of item
Raises ------ lsst.pex.exceptions.NotFoundError If the item does not exist. """
"""Return an item as a scalar
If the item has more than one value then the last value is returned
Parameters ---------- name : ``str`` Name of item
Raises ------ lsst.pex.exceptions.NotFoundError If the item does not exist. """
"""Set the value of an item
If the item already exists it is silently replaced; the types need not match.
Parameters ---------- name : ``str`` Name of item value : any supported type Value of item; may be a scalar or array """
"""Append one or more values to a given item, which need not exist
If the item exists then the new value(s) are appended; otherwise it is like calling `set`
Parameters ---------- name : ``str`` Name of item value : any supported type Value of item; may be a scalar or array
Notes ----- If `value` is an ``lsst.daf.base.PropertySet`` items are added using dotted names (e.g. if name="a" and value contains an item "b" which is another PropertySet and contains an item "c" which is numeric or string, then the value of "c" is added as "a.b.c", appended to the existing values of "a.b.c" if any (in which case the types must be compatible).
Raises ------ lsst::pex::exceptions::TypeError If the type of `value` is incompatible with the existing value of the item. """
else: self.getComment(name)))
"""Return an ordered dictionary with all properties in the order that they were inserted. """
# It would be a bit simpler to use __setstate__ and __getstate__. # However, implementing __setstate__ in Python causes segfaults # because pickle creates a new instance by calling # object.__new__(PropertyList, *args) which bypasses # the pybind11 memory allocation step. |