typeddfs.utils.io_utils
Tools for IO.
Module Contents
- class typeddfs.utils.io_utils.IoUtils
- classmethod get_encoding(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": usesys.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(errors: Optional[str]) Optional[str]
Returns the value passed as``errors=`` in
open. :raises ValueError: If invalid
- classmethod is_binary(path: typeddfs.utils._utils.PathLike) bool
- classmethod path_or_buff_compression(path_or_buff, kwargs) typeddfs.file_formats.CompressionFormat
- classmethod read(path_or_buff, *, mode: str = 'r', **kwargs) str
Reads using Pandas’s
get_handle. By default (unlesscompression=is set), infers the compression type from the filename suffix. (e.g..csv.gz).
- classmethod tmp_path(path: typeddfs.utils._utils.PathLike, extra: str = 'tmp') pathlib.Path
- classmethod verify_can_read_files(*paths: Union[str, pathlib.Path], missing_ok: bool = False, attempt: 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
attempt – Actually try opening
- Returns
If a path is not a file (modulo existence) or doesn’t have ‘W’ set
- Return type
- classmethod verify_can_write_dirs(*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
- classmethod verify_can_write_files(*paths: Union[str, pathlib.Path], missing_ok: bool = False, attempt: 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
attempt – Actually try opening
- Returns
If a path is not a file (modulo existence) or doesn’t have ‘W’ set
- Return type
- classmethod write(path_or_buff, content, *, mode: str = 'w', atomic: bool = False, **kwargs) Optional[str]
Writes using Pandas’s
get_handle. By default (unlesscompression=is set), infers the compression type from the filename suffix (e.g..csv.gz).