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
resolvefirst
- classmethod freeze(cls, v: Any) Anyο
Returns
vor 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
vitself, atypeddfs.utils.FrozeSet(subclass oftyping.AbstractSet), atypeddfs.utils.FrozeList(subclass oftyping.Sequence), or atypeddfs.utils.FrozeDict(subclass oftyping.Mapping). int, float, str, np.generic, and tuple are always returned as-is.- Raises
AttributeError β If
vis 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
vis anIteratoror 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 itemswill be usedlast β Probably βandβ, βorβ, βand/orβ, or ββ Spaces are added/removed as needed if
suffixis 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 elephantjoin_to_str(["cat", "dog"], last="and") # cat and dogjoin_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