Skip to content

Commit 59c24cb

Browse files
mKlepschim-vinicius
authored and
im-vinicius
committed
Typing: Narrow down types of arguments (NDFrame) pandas-dev#10 (pandas-dev#52754)
* improved specificationfor date_unit in to_json more precisely * improved specification mode in to_hdf * added the Literal to complib of to_hdf * improved format for to_hdf * address PR review * Update generic.py removed the new line in the import * ran "pre-commit" to fix trailing whitespace
1 parent a2b6f12 commit 59c24cb

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

pandas/_typing.py

+1
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@ def closed(self) -> bool:
419419
AlignJoin = Literal["outer", "inner", "left", "right"]
420420
DtypeBackend = Literal["pyarrow", "numpy_nullable"]
421421

422+
TimeUnit = Literal["s", "ms", "us", "ns"]
422423
OpenFileErrors = Literal[
423424
"strict",
424425
"ignore",

pandas/core/generic.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
TimedeltaConvertibleTypes,
8383
TimeNonexistent,
8484
TimestampConvertibleTypes,
85+
TimeUnit,
8586
ValueKeyFunc,
8687
WriteBuffer,
8788
WriteExcelBuffer,
@@ -2284,7 +2285,7 @@ def to_json(
22842285
date_format: str | None = None,
22852286
double_precision: int = 10,
22862287
force_ascii: bool_t = True,
2287-
date_unit: str = "ms",
2288+
date_unit: TimeUnit = "ms",
22882289
default_handler: Callable[[Any], JSONSerializable] | None = None,
22892290
lines: bool_t = False,
22902291
compression: CompressionOptions = "infer",
@@ -2564,11 +2565,11 @@ def to_hdf(
25642565
self,
25652566
path_or_buf: FilePath | HDFStore,
25662567
key: str,
2567-
mode: str = "a",
2568+
mode: Literal["a", "w", "r+"] = "a",
25682569
complevel: int | None = None,
2569-
complib: str | None = None,
2570+
complib: Literal["zlib", "lzo", "bzip2", "blosc"] | None = None,
25702571
append: bool_t = False,
2571-
format: str | None = None,
2572+
format: Literal["fixed", "table"] | None = None,
25722573
index: bool_t = True,
25732574
min_itemsize: int | dict[str, int] | None = None,
25742575
nan_rep=None,

0 commit comments

Comments
 (0)