8.1.1.2. pandasdmx.utils package¶
8.1.1.2.1. Submodules¶
8.1.1.2.2. pandasdmx.utils.aadict module¶
8.1.1.2.3. pandasdmx.utils.anynamedtuple module¶
-
pandasdmx.utils.anynamedtuple.
namedtuple
(typename, field_names, verbose=False, rename=False)[source]¶ Returns a new subclass of tuple with named fields. This is a patched version of collections.namedtuple from the stdlib. Unlike the latter, it accepts non-identifier strings as field names. All values are accessible through dict syntax. Fields whose names are identifiers are also accessible via attribute syntax as in ordinary namedtuples, alongside traditional indexing. This feature is needed as SDMX allows field names to contain ‘-‘.
>>> Point = namedtuple('Point', ['x', 'y']) >>> Point.__doc__ # docstring for the new class 'Point(x, y)' >>> p = Point(11, y=22) # instantiate with positional args or keywords >>> p[0] + p[1] # indexable like a plain tuple 33 >>> x, y = p # unpack like a regular tuple >>> x, y (11, 22) >>> p.x + p.y # fields also accessable by name 33 >>> d = p._asdict() # convert to a dictionary >>> d['x'] 11 >>> Point(**d) # convert from a dictionary Point(x=11, y=22) >>> p._replace(x=100) # _replace() is like str.replace() but targets named fields Point(x=100, y=22)
8.1.1.2.4. Module contents¶
module pandasdmx.utils - helper classes and functions
-
class
pandasdmx.utils.
DictLike
[source]¶ Bases:
pandasdmx.utils.aadict.aadict
Thin wrapper around dict type
It allows attribute-like item access, has a
find()
method and inherits other useful features from aadict.-
find
(search_str, by='name', language='en')[source]¶ Select values by attribute
Parameters: - searchstr (str) – the string to search for
- by (str) – the name of the attribute to search by, defaults to ‘name’
The specified attribute must be either a string
or a dict mapping language codes to strings.
Such attributes occur, e.g. in
pandasdmx.model.NameableArtefact
which is a base class forpandasdmx.model.DataFlowDefinition
and many others. - language (str) – language code specifying the language of the text to be searched, defaults to ‘en’
Returns: - items where value.<by> contains the search_str. International strings
stored as dict with language codes as keys are searched. Capitalization is ignored.
Return type:
-
-
class
pandasdmx.utils.
LazyDict
(func, *args, **kwargs)[source]¶ Bases:
dict
lazily comput values by calling func(k)
-
class
pandasdmx.utils.
NamedTupleFactory
[source]¶ Bases:
object
Wrap namedtuple function from the collections stdlib module to return a singleton if a nametuple with the same field names has already been created.
-
cache
= {('dim', 'value', 'attrib'): <class 'pandasdmx.utils.SeriesObservation'>, ('key', 'value', 'attrib'): <class 'pandasdmx.utils.GenericObservation'>}¶
-
-
pandasdmx.utils.
concat_namedtuples
(*tup, **kwargs)[source]¶ Concatenate 2 or more namedtuples. The new namedtuple type is provided by
NamedTupleFactory
return new namedtuple instance