great_expectations.marshmallow__shade.utils

Utility methods for marshmallow.

Module Contents

Classes

_Missing()

Functions

is_generator(obj)

Return True if obj is a generator

is_iterable_but_not_string(obj)

Return True if obj is an iterable object that isn’t a string.

is_collection(obj)

Return True if obj is a collection type, e.g list, tuple, queryset.

is_instance_or_subclass(val, class_)

Return True if val is either a subclass or instance of class_.

is_keyed_tuple(obj)

Return True if obj has keyed tuple behavior, such as

pprint(obj, *args, **kwargs)

Pretty-printing function that can pretty-print OrderedDicts

is_aware(datetime: dt.datetime)

from_rfc(datestring: str)

Parse a RFC822-formatted datetime string and return a datetime object.

rfcformat(datetime: dt.datetime)

Return the RFC822-formatted representation of a datetime object.

get_fixed_timezone(offset: typing.Union[int, float, dt.timedelta])

Return a tzinfo instance with a fixed offset from UTC.

from_iso_datetime(value)

Parse a string and return a datetime.datetime.

from_iso_time(value)

Parse a string and return a datetime.time.

from_iso_date(value)

Parse a string and return a datetime.date.

isoformat(datetime: dt.datetime)

Return the ISO8601-formatted representation of a datetime object.

to_iso_date(date: dt.date)

ensure_text_type(val: typing.Union[str, bytes])

pluck(dictlist: typing.List[typing.Dict[str, typing.Any]], key: str)

Extracts a list of dictionary values from a list of dictionaries.

get_value(obj, key: typing.Union[int, str], default=missing)

Helper for pulling a keyed value off various types of objects. Fields use

_get_value_for_keys(obj, keys, default)

_get_value_for_key(obj, key, default)

set_value(dct: typing.Dict[str, typing.Any], key: str, value: typing.Any)

Set a value in a dict. If key contains a ‘.’, it is assumed

callable_or_raise(obj)

Check that an object is callable, else raise a ValueError.

_signature(func: typing.Callable)

get_func_args(func: typing.Callable)

Given a callable, return a list of argument names. Handles

resolve_field_instance(cls_or_instance)

Return a Schema instance from a Schema class or instance.

great_expectations.marshmallow__shade.utils.EXCLUDE = exclude
great_expectations.marshmallow__shade.utils.INCLUDE = include
great_expectations.marshmallow__shade.utils.RAISE = raise
class great_expectations.marshmallow__shade.utils._Missing
__bool__(self)
__copy__(self)
__deepcopy__(self, _)
__repr__(self)

Return repr(self).

great_expectations.marshmallow__shade.utils.missing
great_expectations.marshmallow__shade.utils.is_generator(obj) → bool

Return True if obj is a generator

great_expectations.marshmallow__shade.utils.is_iterable_but_not_string(obj) → bool

Return True if obj is an iterable object that isn’t a string.

great_expectations.marshmallow__shade.utils.is_collection(obj) → bool

Return True if obj is a collection type, e.g list, tuple, queryset.

great_expectations.marshmallow__shade.utils.is_instance_or_subclass(val, class_) → bool

Return True if val is either a subclass or instance of class_.

great_expectations.marshmallow__shade.utils.is_keyed_tuple(obj) → bool

Return True if obj has keyed tuple behavior, such as namedtuples or SQLAlchemy’s KeyedTuples.

great_expectations.marshmallow__shade.utils.pprint(obj, *args, **kwargs) → None

Pretty-printing function that can pretty-print OrderedDicts like regular dictionaries. Useful for printing the output of marshmallow.Schema.dump().

great_expectations.marshmallow__shade.utils.is_aware(datetime: dt.datetime) → bool
great_expectations.marshmallow__shade.utils.from_rfc(datestring: str) → dt.datetime

Parse a RFC822-formatted datetime string and return a datetime object.

https://stackoverflow.com/questions/885015/how-to-parse-a-rfc-2822-date-time-into-a-python-datetime # noqa: B950

great_expectations.marshmallow__shade.utils.rfcformat(datetime: dt.datetime) → str

Return the RFC822-formatted representation of a datetime object.

Parameters

datetime (datetime) – The datetime.

great_expectations.marshmallow__shade.utils._iso8601_datetime_re
great_expectations.marshmallow__shade.utils._iso8601_date_re
great_expectations.marshmallow__shade.utils._iso8601_time_re
great_expectations.marshmallow__shade.utils.get_fixed_timezone(offset: typing.Union[int, float, dt.timedelta]) → dt.timezone

Return a tzinfo instance with a fixed offset from UTC.

great_expectations.marshmallow__shade.utils.from_iso_datetime(value)

Parse a string and return a datetime.datetime.

This function supports time zone offsets. When the input contains one, the output uses a timezone with a fixed offset from UTC.

great_expectations.marshmallow__shade.utils.from_iso_time(value)

Parse a string and return a datetime.time.

This function doesn’t support time zone offsets.

great_expectations.marshmallow__shade.utils.from_iso_date(value)

Parse a string and return a datetime.date.

great_expectations.marshmallow__shade.utils.isoformat(datetime: dt.datetime) → str

Return the ISO8601-formatted representation of a datetime object.

Parameters

datetime (datetime) – The datetime.

great_expectations.marshmallow__shade.utils.to_iso_date(date: dt.date) → str
great_expectations.marshmallow__shade.utils.ensure_text_type(val: typing.Union[str, bytes]) → str
great_expectations.marshmallow__shade.utils.pluck(dictlist: typing.List[typing.Dict[str, typing.Any]], key: str)

Extracts a list of dictionary values from a list of dictionaries.

>>> dlist = [{'id': 1, 'name': 'foo'}, {'id': 2, 'name': 'bar'}]
>>> pluck(dlist, 'id')
[1, 2]
great_expectations.marshmallow__shade.utils.get_value(obj, key: typing.Union[int, str], default=missing)

Helper for pulling a keyed value off various types of objects. Fields use this method by default to access attributes of the source object. For object x and attribute i, this method first tries to access x[i], and then falls back to x.i if an exception is raised.

Warning

If an object x does not raise an exception when x[i] does not exist, get_value will never check the value x.i. Consider overriding marshmallow.fields.Field.get_value in this case.

great_expectations.marshmallow__shade.utils._get_value_for_keys(obj, keys, default)
great_expectations.marshmallow__shade.utils._get_value_for_key(obj, key, default)
great_expectations.marshmallow__shade.utils.set_value(dct: typing.Dict[str, typing.Any], key: str, value: typing.Any)

Set a value in a dict. If key contains a ‘.’, it is assumed be a path (i.e. dot-delimited string) to the value’s location.

>>> d = {}
>>> set_value(d, 'foo.bar', 42)
>>> d
{'foo': {'bar': 42}}
great_expectations.marshmallow__shade.utils.callable_or_raise(obj)

Check that an object is callable, else raise a ValueError.

great_expectations.marshmallow__shade.utils._signature(func: typing.Callable) → typing.List[str]
great_expectations.marshmallow__shade.utils.get_func_args(func: typing.Callable) → typing.List[str]

Given a callable, return a list of argument names. Handles functools.partial objects and class-based callables.

Changed in version 3.0.0a1: Do not return bound arguments, eg. self.

great_expectations.marshmallow__shade.utils.resolve_field_instance(cls_or_instance)

Return a Schema instance from a Schema class or instance.

Parameters

cls_or_instance (type|Schema) – Marshmallow Schema class or instance.