From 25b1dd96323f247624ebaea31d8d26f973152d66 Mon Sep 17 00:00:00 2001 From: Maximilian Klepsch Date: Tue, 18 Apr 2023 14:27:28 +0000 Subject: [PATCH 1/7] improved specificationfor date_unit in to_json more precisely --- pandas/core/generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 582a043a8a78a..3064da06ed05e 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -2276,7 +2276,7 @@ def to_json( date_format: str | None = None, double_precision: int = 10, force_ascii: bool_t = True, - date_unit: str = "ms", + date_unit: Literal["s", "ms", "us", "ns"] = "ms", default_handler: Callable[[Any], JSONSerializable] | None = None, lines: bool_t = False, compression: CompressionOptions = "infer", From 899e30f4a19bf0e5a998a920486042142d605fd8 Mon Sep 17 00:00:00 2001 From: Maximilian Klepsch Date: Tue, 18 Apr 2023 14:32:12 +0000 Subject: [PATCH 2/7] improved specification mode in to_hdf --- pandas/core/generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 3064da06ed05e..da6a648d4c7c4 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -2556,7 +2556,7 @@ 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, append: bool_t = False, From 297e3f08d7b21d6787ece93a003874e07ac1cebf Mon Sep 17 00:00:00 2001 From: Maximilian Klepsch Date: Tue, 18 Apr 2023 14:35:51 +0000 Subject: [PATCH 3/7] added the Literal to complib of to_hdf --- pandas/core/generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index da6a648d4c7c4..4bfefe8bb1ec0 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -2558,7 +2558,7 @@ def to_hdf( key: str, mode: Literal["a", "w", "r+"] = "a", complevel: int | None = None, - complib: str | None = None, + complib: ["zlib", "lzo", "bzip2", "blosc"] | None = None, append: bool_t = False, format: str | None = None, index: bool_t = True, From 348c02a9e05569988b84184c04f4a32dcad7e53e Mon Sep 17 00:00:00 2001 From: Maximilian Klepsch Date: Tue, 18 Apr 2023 14:40:37 +0000 Subject: [PATCH 4/7] improved format for to_hdf --- pandas/core/generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 4bfefe8bb1ec0..eeb5dfbe4fd8e 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -2560,7 +2560,7 @@ def to_hdf( complevel: int | None = None, complib: ["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, From 1e5bc564982aedc9f0bd1342f02ce2700d827dc0 Mon Sep 17 00:00:00 2001 From: Maximilian Klepsch Date: Tue, 18 Apr 2023 15:21:04 +0000 Subject: [PATCH 5/7] address PR review --- pandas/_typing.py | 3 +++ pandas/core/generic.py | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pandas/_typing.py b/pandas/_typing.py index de02a549856ab..b6d2a1bfcf5ee 100644 --- a/pandas/_typing.py +++ b/pandas/_typing.py @@ -390,3 +390,6 @@ def closed(self) -> bool: ] AlignJoin = Literal["outer", "inner", "left", "right"] DtypeBackend = Literal["pyarrow", "numpy_nullable"] + +#TimeUnit +TimeUnit = Literal["s", "ms", "us", "ns"] \ No newline at end of file diff --git a/pandas/core/generic.py b/pandas/core/generic.py index eeb5dfbe4fd8e..147ec40b01048 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -80,10 +80,12 @@ TimedeltaConvertibleTypes, TimeNonexistent, TimestampConvertibleTypes, + TimeUnit, ValueKeyFunc, WriteBuffer, WriteExcelBuffer, npt, + ) from pandas.compat._optional import import_optional_dependency from pandas.compat.numpy import function as nv @@ -2276,7 +2278,7 @@ def to_json( date_format: str | None = None, double_precision: int = 10, force_ascii: bool_t = True, - date_unit: Literal["s", "ms", "us", "ns"] = "ms", + date_unit: TimeUnit = "ms", default_handler: Callable[[Any], JSONSerializable] | None = None, lines: bool_t = False, compression: CompressionOptions = "infer", @@ -2558,7 +2560,7 @@ def to_hdf( key: str, mode: Literal["a", "w", "r+"] = "a", complevel: int | None = None, - complib: ["zlib", "lzo", "bzip2", "blosc"] | None = None, + complib: Literal["zlib", "lzo", "bzip2", "blosc"] | None = None, append: bool_t = False, format: Literal["fixed", "table"] | None = None, index: bool_t = True, From 837f7ed4d619a485a934315c8446fa7472434ac1 Mon Sep 17 00:00:00 2001 From: mKlepsch <37306042+mKlepsch@users.noreply.github.com> Date: Thu, 20 Apr 2023 11:53:05 +0200 Subject: [PATCH 6/7] Update generic.py removed the new line in the import --- pandas/core/generic.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index f7c4828197558..c6449c0db9fe5 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -85,8 +85,7 @@ ValueKeyFunc, WriteBuffer, WriteExcelBuffer, - npt, - + npt, ) from pandas.compat._optional import import_optional_dependency from pandas.compat.numpy import function as nv From c488ac88adb3c249c8820426d55cae8e6ac327f6 Mon Sep 17 00:00:00 2001 From: Maximilian Klepsch Date: Mon, 24 Apr 2023 10:51:18 +0000 Subject: [PATCH 7/7] ran "pre-commit" to fix trailing whitespace --- pandas/core/generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index c6449c0db9fe5..9808854f6cc43 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -85,7 +85,7 @@ ValueKeyFunc, WriteBuffer, WriteExcelBuffer, - npt, + npt, ) from pandas.compat._optional import import_optional_dependency from pandas.compat.numpy import function as nv