typeddfs.utils.io_utils

Tools for IO.

Module Contents

class typeddfs.utils.io_utils.IoUtils
classmethod get_encoding(cls, encoding: str = 'utf-8') str

Returns a text encoding from a more flexible string. Ignores hyphens and lowercases the string. Permits these nonstandard shorthands:

  • "platform": use sys.getdefaultencoding() on the fly

  • "utf8(bom)": use "utf-8-sig" on Windows; "utf-8" otherwise

  • "utf16(bom)": use "utf-16-sig" on Windows; "utf-16" otherwise

  • "utf32(bom)": use "utf-32-sig" on Windows; "utf-32" otherwise

classmethod get_encoding_errors(cls, errors: Optional[str]) Optional[str]

Returns the value passed as``errors=`` in open. :raises ValueError: If invalid

classmethod read(cls, path_or_buff, *, mode: str = 'r', **kwargs) str

Reads using Pandas’s get_handle. By default (unless compression= is set), infers the compression type from the filename suffix (e.g. .csv.gz).

classmethod verify_can_write_dirs(cls, *paths: Union[str, pathlib.Path], missing_ok: bool = False) None

Checks that all directories can be written to, to ensure atomicity before operations.

Parameters
  • *paths – The directories

  • missing_ok – Don’t raise an error if a path doesn’t exist

Returns

If a path is not a directory (modulo existence) or doesn’t have ‘W’ set

Return type

WritePermissionsError

classmethod verify_can_write_files(cls, *paths: Union[str, pathlib.Path], missing_ok: bool = False) None

Checks that all files can be written to, to ensure atomicity before operations.

Parameters
  • *paths – The files

  • missing_ok – Don’t raise an error if a path doesn’t exist

Returns

If a path is not a file (modulo existence) or doesn’t have ‘W’ set

Return type

WritePermissionsError

classmethod write(cls, path_or_buff, content, *, mode: str = 'w', **kwargs) Optional[str]

Writes using Pandas’s get_handle. By default (unless compression= is set), infers the compression type from the filename suffix (e.g. .csv.gz).