typeddfs.utils.misc_utils

Misc tools for typed-dfs.

Module Contents

class typeddfs.utils.misc_utils.MiscUtils
classmethod choose_table_format(cls, *, path: typeddfs.utils._utils.PathLike, fmt: Union[None, tabulate.TableFormat, str] = None, default: str = 'plain') Union[str, tabulate.TableFormat]

Makes a best-effort guess of a good tabulate format from a path name.

classmethod delete_file(cls, path: typeddfs.utils._utils.PathLike, *, missing_ok: bool = False, alg: str = _DEFAULT_HASH_ALG, attrs_suffix: str = _DEFAULT_ATTRS_SUFFIX, rm_if_empty: bool = True) None

Deletes a file, plus the checksum file and/or directory entry, and .attrs.json.

Parameters
  • path – The path to delete

  • missing_ok – ok if the path does not exist (will still delete any associated paths)

  • alg – The checksum algorithm

  • attrs_suffix – The suffix for attrs file (normally .attrs.json)

  • rm_if_empty – Remove the dir checksum file if it contains no additional paths

Raises

typeddfs.df_errors.PathNotRelativeError – To avoid, try calling resolve first

classmethod freeze(cls, v: Any) Any

Returns v or a hashable view of it. Note that the returned types must be hashable but might not be ordered. You can generally add these values as DataFrame elements, but you might not be able to sort on those columns.

Parameters

v – Any value

Returns

Either v itself, a typeddfs.utils.FrozeSet (subclass of typing.AbstractSet), a typeddfs.utils.FrozeList (subclass of typing.Sequence), or a typeddfs.utils.FrozeDict (subclass of typing.Mapping). int, float, str, np.generic, and tuple are always returned as-is.

Raises
  • AttributeError – If v is not hashable and could not converted to a FrozeSet, FrozeList, or FrozeDict, or if one of the elements for one of the above types is not hashable.

  • TypeError – If v is an Iterator or collections.deque`

classmethod join_to_str(cls, *items: Any, last: str, sep: str = ', ') str

Joins items to something like β€œcat, dog, and pigeon” or β€œcat, dog, or pigeon”.

Parameters
  • items – Items to join; str(item) for item in items will be used

  • last – Probably β€œand”, β€œor”, β€œand/or”, or β€œβ€ Spaces are added/removed as needed if suffix is alphanumeric or β€œand/or”, after stripping whitespace off the ends.

  • sep – Used to separate all words; include spaces as desired

Examples

  • join_to_str(["cat", "dog", "elephant"], last="and")  # cat, dog, and elephant

  • join_to_str(["cat", "dog"], last="and")  # cat and dog

  • join_to_str(["cat", "dog", "elephant"], last="", sep="/")  # cat/dog/elephant

classmethod plain_table_format(cls, *, sep: str = ' ', **kwargs) tabulate.TableFormat

Creates a simple tabulate style using a column-delimiter sep.

Returns

A tabulate TableFormat, which can be passed as a style

classmethod table_format(cls, fmt: str) tabulate.TableFormat

Gets a tabulate style by name.

Returns

A TableFormat, which can be passed as a style

classmethod table_formats(cls) Sequence[str]

Returns the names of styles for tabulate.