API Reference

Subpackages

Submodules

fireant.formats module

fireant.formats.coerce_type(value)[source]
fireant.formats.date_as_millis(value)[source]
fireant.formats.dimension_value(value)[source]

Format a dimension value. This will coerce the raw string or date values into a proper primitive value like a string, float, or int.

Parameters:
  • value – The raw str or datetime value
  • str_date – When True, dates and datetimes will be converted to ISO strings. The time is omitted for dates. When False, the datetime will be converted to a POSIX timestamp (millis-since-epoch).
fireant.formats.metric_display(value, prefix=None, suffix=None, precision=None)[source]

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

Parameters:
  • value – The raw metric value.
  • prefix – An optional prefix.
  • suffix – An optional suffix.
  • precision – The decimal precision, the number of decimal places to round to.
Returns:

A formatted string containing the display value for the metric.

fireant.formats.metric_value(value)[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.

fireant.settings module

fireant.utils module

fireant.utils.chunks(l, n)[source]

Yield successive n-sized chunks from l.

fireant.utils.filter_duplicates(iterable)[source]
fireant.utils.flatten(items)[source]
fireant.utils.format_dimension_key(key)[source]
fireant.utils.format_key(key, prefix=None)[source]
fireant.utils.format_metric_key(key)[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.groupby_first_level(index)[source]
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.merge_dicts(*dict_args)[source]

Given any number of dicts, shallow copy and merge into a new dict, precedence goes to key value pairs in latter dicts.

https://stackoverflow.com/questions/38987/how-to-merge-two-python-dictionaries-in-a-single-expression

fireant.utils.ordered_distinct_list(l)[source]
fireant.utils.ordered_distinct_list_by_attr(l, attr='key')[source]
fireant.utils.reduce_data_frame_levels(data_frame, level)[source]
fireant.utils.repr_field_key(key)[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.slice_first(item)[source]
fireant.utils.wrap_list(value)[source]

Module contents