fireant package

Submodules

fireant.exceptions module

exception fireant.exceptions.SlicerException[source]

Bases: Exception

fireant.formats module

fireant.formats.date_as_millis(*args, **kwargs)
fireant.formats.date_as_string(*args, **kwargs)
fireant.formats.display_value(value, field, date_as=functools.partial(<function apply_kwargs>, <function date_as_string>))[source]

Converts a metric value into the display value by applying formatting.

Parameters:
  • value – The raw metric value.
  • field – The slicer field that the value represents.
  • date_as – A format function for datetimes.
Returns:

A formatted string containing the display value for the metric.

fireant.formats.json_value(value)[source]

This function will return only values safe for JSON

fireant.formats.raw_value(value, field, date_as=functools.partial(<function apply_kwargs>, <function date_as_string>))[source]

Converts a raw metric value into a safe type. This will change dates into strings, NaNs into Nones, and np types into their corresponding python types.

Parameters:
  • value – The raw metric value.
  • field – The slicer field that the value represents.
  • date_as
fireant.formats.return_none(*args, **kwargs)
fireant.formats.safe_value(value)[source]
fireant.formats.wrap_styling(*args, **kwargs)

fireant.reference_helpers module

fireant.reference_helpers.reference_alias(metric, reference)[source]

Format a metric key for a reference.

Returns:A string that is used as the key for a reference metric.
fireant.reference_helpers.reference_label(metric, reference)[source]

Format a metric label for a reference.

Returns:A string that is used as the display value for a reference metric.
fireant.reference_helpers.reference_prefix(metric, reference)[source]

Return the prefix for a metric displayed for a reference (or no Reference)

Returns:A string that is used as the prefix for a reference metric.
fireant.reference_helpers.reference_suffix(metric, reference)[source]

Return the suffix for a metric displayed for a reference (or no Reference)

Returns:A string that is used as the suffix for a reference metric.

fireant.settings module

fireant.utils module

fireant.utils.alias_for_alias_selector(f_alias)[source]
fireant.utils.alias_selector(alias)[source]
fireant.utils.apply_kwargs(f, *args, **kwargs)[source]
fireant.utils.chunks(l, n)[source]

Yield successive n-sized chunks from l.

fireant.utils.filter_kwargs(f)[source]

Removes any kwargs from function call that are not accepted by the called function.

Parameters:f
Returns:
fireant.utils.flatten(items)[source]
fireant.utils.getdeepattr(d, keys, default_value=None)[source]

Similar to the built-in getattr, this function accepts a list/tuple of keys to get a value deep in a dict

Given the following dict structure

d = {
  'A': {
    '0': {
      'a': 1,
      'b': 2,
    }
  },
}

Calling getdeepattr with a key path to a value deep in the structure will return that value. If the value or any of the objects in the key path do not exist, then the default value is returned.

assert 1 == getdeepattr(d, ('A', '0', 'a'))
assert 2 == getdeepattr(d, ('A', '0', 'b'))
assert 0 == getdeepattr(d, ('A', '0', 'c'), default_value=0)
assert 0 == getdeepattr(d, ('X', '0', 'a'), default_value=0)
Parameters:
  • d – A dict value with nested dict attributes.
  • keys – A list/tuple path of keys in d to the desired value
  • default_value – A default value that will be returned if the path keys does not yield a value.
Returns:

The value following the path keys or default_value

fireant.utils.groupby(items, by)[source]

Group items using a function to derive a key.

Parameters:
  • items – The items to group
  • by – A lambda function to create a key based on the item
Returns:

an Ordered dict

fireant.utils.immutable(func)[source]

Decorator for wrapper “builder” functions. These are functions on the Query class or other classes used for building queries which mutate the query and return self. To make the build functions immutable, this decorator is used which will deepcopy the current instance. This decorator will return the return value of the inner function or the new copy of the instance. The inner function does not need to return self.

fireant.utils.ordered_distinct_list(l)[source]
fireant.utils.ordered_distinct_list_by_attr(l, attr='alias')[source]
fireant.utils.reduce_data_frame_levels(data_frame, level)[source]
fireant.utils.setdeepattr(d, keys, value)[source]

Similar to the built-in setattr, this function accepts a list/tuple of keys to set a value deep in a dict

Given the following dict structure

d = {
  'A': {
    '0': {
      'a': 1,
      'b': 2,
    }
  },
}

Calling setdeepattr with a key path to a value deep in the structure will set that value. If the value or any of the objects in the key path do not exist, then a dict will be created.

# Overwrites the value in `d` at A.0.a, which was 1, to 3
setdeepattr(d, ('A', '0', 'a'), 3)

# Adds an entry in `d` to A.0 with the key 'c' and the value 3
setdeepattr(d, ('A', '0', 'c'), 3)

# Adds an entry in `d` with the key 'X' and the value a new dict
# Adds an entry in `d` to `X` with the key '0' and the value a new dict
# Adds an entry in `d` to `X.0` with the key 'a' and the value 0
setdeepattr(d, ('X', '0', 'a'), 0)
Parameters:
  • d – A dict value with nested dict attributes.
  • keys – A list/tuple path of keys in d to the desired value
  • value – The value to set at the given path keys.
fireant.utils.wrap_list(value, wrapper=<class 'list'>)[source]