pandasdmx.utils package Submodules pandasdmx.utils.aadict module

class pandasdmx.utils.aadict.aadict

Bases: dict

A dict subclass that allows attribute access to be synonymous with item access, e.g. mydict.attribute == mydict['attribute']. It also provides several other useful helper methods, such as pick() and omit().

static d2a(subject)
static d2ar(subject)
update(*args, **kw) pandasdmx.utils.anynamedtuple module

pandasdmx.utils.anynamedtuple.namedtuple(typename, field_names, verbose=False, rename=False)

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
>>> x, y = p                        # unpack like a regular tuple
>>> x, y
(11, 22)
>>> p.x + p.y                       # fields also accessable by name
>>> d = p._asdict()                 # convert to a dictionary
>>> d['x']
>>> 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) Module contents

module pandasdmx.utils - helper classes and functions

class pandasdmx.utils.DictLike

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.


return an arbitrary or the only value. If dict is empty, raise KeyError.


return values() as unordered list

find(search_str, by='name', language='en')

Select values by attribute

  • 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 for pandasdmx.model.DataFlowDefinition and many others.
  • language (str) – language code specifying the language of the text to be searched, defaults to ‘en’

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.NamedTupleFactory

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 = {('key', 'value', 'attrib'): <class 'pandasdmx.utils.GenericObservation'>, ('dim', 'value', 'attrib'): <class 'pandasdmx.utils.SeriesObservation'>}
pandasdmx.utils.concat_namedtuples(*tup, **kwargs)

Concatenate 2 or more namedtuples. The new namedtuple type is provided by NamedTupleFactory return new namedtuple instance