ballet.util package

class ballet.util.DeepcopyMixin[source]

Bases: object

ballet.util.asarray2d(a)[source]

Cast to 2d array

Return type

ndarray

ballet.util.dfilter(call, pred)[source]

Decorate a callable with a filter that accepts a predicate

Example:

>>> @dfilter(lambda x: x >= 0)
... def numbers():
...     return [-1, 2, 0, -2]
[2, 0]
ballet.util.dont_log_nonnegative(call, logger=<Logger ballet (WARNING)>)[source]
ballet.util.falsy(o)[source]

Check whether o is falsy

In this case, a falsy value is one of the following: 1. the singleton value False 2. the string ‘false’ (ignoring case) 3. the empty string

Return type

bool

ballet.util.get_arr_desc(arr)[source]

Get array description, in the form ‘<array type> <array shape>’

Return type

str

ballet.util.has_nans(obj)[source]

Check if obj has any NaNs

Compatible with different behavior of np.isnan, which sometimes applies over all axes (py35+) and sometimes does not (py34).

Return type

bool

ballet.util.indent(text, n=4)[source]

Indent each line of text by n spaces

Return type

str

ballet.util.load_sklearn_df(name)[source]
Return type

Tuple[DataFrame, DataFrame]

ballet.util.make_plural_suffix(obj, suffix='s')[source]
Return type

str

ballet.util.nonnegative(call, name=None)[source]

Warn if the function’s return value is negative and set it to 0

ballet.util.one_or_raise(seq)[source]
Return type

~_T

ballet.util.quiet(call)[source]
ballet.util.raiseifnone(call)[source]

Decorate a function to raise a ValueError if result is None

ballet.util.skipna(a, b, *c, how='left')[source]

Drop rows of both a and b corresponding to missing values

The length of a and b along the first dimension must be equal.

Parameters
  • a (ndarray) – first array

  • b (ndarray) – second array

  • *c – any additional arrays

  • how (str) – how to determine the rows to drop, one of ‘left’, ‘any’, or ‘all’. If left, then any row in which a has a missing value is dropped. If any, then any row in which at least one of a, b, or additional arrays has a missing value is dropped. If all , then any row in which all of a, b, and additional arrays has a missing value is dropped. Defaults to left.

Returns

tuple of a, b, and any additional arrays where a, b, and any additional arrays are guaranteed to be the same length with missing values removed according to how.

ballet.util.truthy(*a, **kw)

Check whether o is truthy

In this case, a truthy value is any value that is not falsy.

ballet.util.warn(msg)[source]

Issue a warning message of category BalletWarning