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?

abstract property as_polars

As which object should polars see this instance for ingestion?

class FlexiDate(date)[source]

Bases: CustomField

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

Parameters:

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

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.

property as_np

Representation a numpy datetime object.

property as_polars

Representation for polars to ingest.

class FlexiTime(time)[source]

Bases: CustomField

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

Parameters:

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

property as_date

Date part as datetime.date object.

property as_dtype

Representation in a pandas DataFrame.

property as_json

Representation to appear in a JSON.

property as_np

Representation a numpy datetime object.

property as_polars

Representation for polars to ingest.

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

class Strip(left=None, right=None)[source]

Bases: ArgRepr

Strip characters from strings on the left and/or right.

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

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

__call__(arg)[source]

Strip characters from strings on the left and/or right.

Parameters:

arg (str) – String to strip characters from left and/or right.

Returns:

The left/right stripped string.

Return type:

str

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