diff --git a/pandas/_typing.py b/pandas/_typing.py index e162f7f1662ee..dc3f2f54a54ca 100644 --- a/pandas/_typing.py +++ b/pandas/_typing.py @@ -419,6 +419,7 @@ def closed(self) -> bool: AlignJoin = Literal["outer", "inner", "left", "right"] DtypeBackend = Literal["pyarrow", "numpy_nullable"] +TimeUnit = Literal["s", "ms", "us", "ns"] OpenFileErrors = Literal[ "strict", "ignore", diff --git a/pandas/core/generic.py b/pandas/core/generic.py index f3de296841510..9e9f28b1dfddb 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -82,6 +82,7 @@ TimedeltaConvertibleTypes, TimeNonexistent, TimestampConvertibleTypes, + TimeUnit, ValueKeyFunc, WriteBuffer, WriteExcelBuffer, @@ -2284,7 +2285,7 @@ def to_json( date_format: str | None = None, double_precision: int = 10, force_ascii: bool_t = True, - date_unit: str = "ms", + date_unit: TimeUnit = "ms", default_handler: Callable[[Any], JSONSerializable] | None = None, lines: bool_t = False, compression: CompressionOptions = "infer", @@ -2564,11 +2565,11 @@ def to_hdf( self, path_or_buf: FilePath | HDFStore, key: str, - mode: str = "a", + mode: Literal["a", "w", "r+"] = "a", complevel: int | None = None, - complib: str | None = None, + complib: Literal["zlib", "lzo", "bzip2", "blosc"] | None = None, append: bool_t = False, - format: str | None = None, + format: Literal["fixed", "table"] | None = None, index: bool_t = True, min_itemsize: int | dict[str, int] | None = None, nan_rep=None,