fields

Special field types for type-annotating class variables in a JsonObject.

class CustomField(arg)[source]

Bases: ABC

Abstract base class for defining custom field types in a JsonObject.

abstract property as_dtype

How should instances appear in cells of a pandas Series?

abstract property as_json

How should instances be represented in a JSON-serializable dict?

class FlexiDate(date)[source]

Bases: object

Flexible wrapper around python’s own datetime.date object.

Parameters:

date – Can be an ISO string of a date or datetime, a datetime.date or a datetime.datetime object, or a pandas.Timestamp.

property as_datetime

Date as a datetime object.

property as_dtype

Representation in a pandas DataFrame.

property as_json

Representation to appear in a JSON.

class FlexiTime(time)[source]

Bases: object

Flexible wrapper around python’s own datetime.datetime object.

Parameters:

time – Can be an ISO string of a date or datetime, a datetime.date or a datetime.datetime object, or a pandas.Timestamp.

property as_dtype

Representation in a pandas DataFrame.

property as_json

Representation to appear in a JSON.

class Lower(lstrip=None, rstrip=None)[source]

Bases: ArgRepr

Lowercase strings, optionally stripping characters left and/or right.

Parameters:
  • lstrip (str, optional) – Characters to strip from the left of a string. Defaults to None, resulting in only whitespaces to be stripped.

  • rstrip (str, optional) – Characters to strip from the right of a string. Defaults to None, resulting in only whitespaces to be stripped.

__call__(arg)[source]

Lowercase strings, optionally stripping left and/or right.

Parameters:

arg (str) – String to put into lowercase and optionally strip characters from.

Returns:

The lowercased and optionally stripped string.

Return type:

str

class Maybe(cast)[source]

Bases: Generic

Type annotation to allow for None values.

Initialize this class with a built-in type, class, or other callable that will cast a given value to the desired type if it is not None. Then calling the callable instance on that value will return the desired type if the value is not None and None if it is.

Parameters:

cast (callable) – Casts value to desired type if value is not None.

Note

Upon instantiation, the generic class can be type-annotated with the return type of cast.

__call__(obj)[source]

Casts value to specified type if value is not None.

Parameters:

obj – Object to type-cast to, or None.

Returns:

Type-cast object or None.

Return type:

object

resolve(path)[source]

Resolve the given path to its full name using pathlib’s Path.

Parameters:

path (str) – The path to resolve.

Returns:

The resolved path.

Return type:

str