atomlib.util
FileOrPath
module-attribute
FileOrPath: TypeAlias = Union[str, Path, TextIOBase, TextIO]
Open text file or path to a file. Use with open_file.
BinaryFileOrPath
module-attribute
Open binary file or path to a file. Use with open_file_binary.
opt_classmethod
Bases: classmethod
, Generic[T, P, U_co]
Decorates a method that may be called either on an instance or the class. If called on the class, a default instance will be constructed before calling the wrapped function.
Source code in atomlib/util.py
CheckedJoinError
map_some
open_file
open_file(
f: FileOrPath,
mode: Union[Literal["r"], Literal["w"]] = "r",
newline: Optional[str] = None,
encoding: Optional[str] = "utf-8",
) -> AbstractContextManager[TextIOBase]
Open the given file for text I/O.
If given a path-like, opens it with the specified settings. Otherwise, make an effort to reconfigure the encoding, and check that it is readable/writable as specified.
Source code in atomlib/util.py
open_file_binary
open_file_binary(
f: BinaryFileOrPath,
mode: Union[Literal["r"], Literal["w"]] = "r",
) -> AbstractContextManager[IOBase]
Open the given file for binary I/O.
If given a path-like, opens it with the specified settings. If given text I/O, reconfigure to binary. Make sure stream is readable/writable, as specified.
Source code in atomlib/util.py
localtime
localtime() -> datetime
Return the current time in a timezone-aware datetime object.
Source code in atomlib/util.py
proc_seed
Process a random seed, which can be any object (or None
for a random seed).
Return it in a form which can be passed to numpy.random.default_rng.
Uses a SHA-256 sum under the hood.
entropy
should be a routine-specific object, to ensure that separate random
routines called using the same seed return uncorrelated results.
Source code in atomlib/util.py
checked_left_join
checked_left_join(
lhs: DataFrame,
rhs: DataFrame,
on: Optional[str] = None,
*,
left_on: Optional[str] = None,
right_on: Optional[str] = None
) -> DataFrame