cuery.context#

Helpers to convert various input formats to iterables of dictionaries.

Attributes#

Functions#

is_iterable(obj)

iterrecords(df[, index])

Iterate over rows of a DataFrame as dictionaries.

contexts_from_dataframe(df, required)

Convert a DataFrame to an interable of dictionaries with variables needed by prompt only.

contexts_from_dict(context, required)

Convert a dict of iterables to an iterable of dicts with keys needed by prompt only.

contexts_from_iterable(context, required)

Convert an iterable of dicts to an iterable of dicts with keys needed by prompt only.

iter_context(context, required)

Ensure context is an iterable of dicts.

context_is_iterable(context)

Check if context is iterable.

Module Contents#

cuery.context.AnyContext#
cuery.context.is_iterable(obj)#
cuery.context.iterrecords(df, index=False)#

Iterate over rows of a DataFrame as dictionaries.

Parameters:
  • df (pandas.DataFrame)

  • index (bool)

cuery.context.contexts_from_dataframe(df, required)#

Convert a DataFrame to an interable of dictionaries with variables needed by prompt only.

Parameters:
  • df (pandas.DataFrame)

  • required (list[str] | None)

Return type:

tuple[collections.abc.Iterable[dict] | None, int]

cuery.context.contexts_from_dict(context, required)#

Convert a dict of iterables to an iterable of dicts with keys needed by prompt only.

Parameters:
  • context (dict)

  • required (list[str] | None)

Return type:

tuple[collections.abc.Iterable[dict] | None, int]

cuery.context.contexts_from_iterable(context, required)#

Convert an iterable of dicts to an iterable of dicts with keys needed by prompt only.

Parameters:
  • context (collections.abc.Iterable[dict])

  • required (list[str] | None)

Return type:

collections.abc.Iterable[dict] | None

cuery.context.iter_context(context, required)#

Ensure context is an iterable of dicts.

Parameters:
  • context (AnyContext | None)

  • required (list[str] | None)

Return type:

tuple[collections.abc.Iterable[dict] | None, int]

cuery.context.context_is_iterable(context)#

Check if context is iterable.

Parameters:

context (AnyContext | None)

Return type:

bool