Skip to content

Commit 49734ca

Browse files
committed
ENH: Add literals
Add literals for limited value inputs
1 parent 163cebd commit 49734ca

File tree

3 files changed

+32
-13
lines changed

3 files changed

+32
-13
lines changed

pandas-stubs/_typing.pyi

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,4 +203,21 @@ GroupByObjectNonScalar = Union[
203203
]
204204
GroupByObject = Union[Scalar, GroupByObjectNonScalar]
205205

206+
StataDateFormat = Literal[
207+
"tc",
208+
"%tc",
209+
"td",
210+
"%td",
211+
"tw",
212+
"%tw",
213+
"tm",
214+
"%tm",
215+
"tq",
216+
"%tq",
217+
"th",
218+
"%th",
219+
"ty",
220+
"%ty",
221+
]
222+
206223
__all__ = ["npt", "type_t"]

pandas-stubs/core/frame.pyi

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ from pandas._typing import (
6969
Scalar,
7070
ScalarT,
7171
SeriesAxisType,
72+
StataDateFormat,
7273
StorageOptions,
7374
StrLike,
7475
T as TType,
@@ -241,13 +242,13 @@ class DataFrame(NDFrame, OpsMixin):
241242
def to_stata(
242243
self,
243244
path: FilePath | WriteBuffer[bytes],
244-
convert_dates: dict[Hashable, str] | None = ...,
245+
convert_dates: dict[HashableT, StataDateFormat] | None = ...,
245246
write_index: _bool = ...,
246247
byteorder: Literal["<", ">", "little", "big"] | None = ...,
247248
time_stamp: _dt.datetime | None = ...,
248249
data_label: _str | None = ...,
249-
variable_labels: dict[Hashable, str] | None = ...,
250-
version: int | None = ...,
250+
variable_labels: dict[HashableT, str] | None = ...,
251+
version: Literal[114, 117, 118, 119] | None = ...,
251252
convert_strl: list[HashableT] | None = ...,
252253
compression: CompressionOptions = ...,
253254
storage_options: StorageOptions = ...,

pandas-stubs/io/stata.pyi

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ from pandas._typing import (
1919
FilePath,
2020
HashableT,
2121
ReadBuffer,
22+
StataDateFormat,
2223
StorageOptions,
2324
WriteBuffer,
2425
)
@@ -138,16 +139,16 @@ class StataWriter(StataParser):
138139
self,
139140
fname: FilePath | WriteBuffer[bytes],
140141
data: DataFrame,
141-
convert_dates: dict[Hashable, str] | None = ...,
142+
convert_dates: dict[HashableT, StataDateFormat] | None = ...,
142143
write_index: bool = ...,
143144
byteorder: str | None = ...,
144145
time_stamp: datetime.datetime | None = ...,
145146
data_label: str | None = ...,
146-
variable_labels: dict[Hashable, str] | None = ...,
147+
variable_labels: dict[HashableT, str] | None = ...,
147148
compression: CompressionOptions = ...,
148149
storage_options: StorageOptions = ...,
149150
*,
150-
value_labels: dict[Hashable, dict[float, str]] | None = ...,
151+
value_labels: dict[HashableT, dict[float, str]] | None = ...,
151152
) -> None: ...
152153
def write_file(self) -> None: ...
153154

@@ -156,34 +157,34 @@ class StataWriter117(StataWriter):
156157
self,
157158
fname: FilePath | WriteBuffer[bytes],
158159
data: DataFrame,
159-
convert_dates: dict[Hashable, str] | None = ...,
160+
convert_dates: dict[HashableT, StataDateFormat] | None = ...,
160161
write_index: bool = ...,
161162
byteorder: str | None = ...,
162163
time_stamp: datetime.datetime | None = ...,
163164
data_label: str | None = ...,
164-
variable_labels: dict[Hashable, str] | None = ...,
165+
variable_labels: dict[HashableT, str] | None = ...,
165166
convert_strl: Sequence[Hashable] | None = ...,
166167
compression: CompressionOptions = ...,
167168
storage_options: StorageOptions = ...,
168169
*,
169-
value_labels: dict[Hashable, dict[float, str]] | None = ...,
170+
value_labels: dict[HashableT, dict[float, str]] | None = ...,
170171
) -> None: ...
171172

172173
class StataWriterUTF8(StataWriter117):
173174
def __init__(
174175
self,
175176
fname: FilePath | WriteBuffer[bytes],
176177
data: DataFrame,
177-
convert_dates: dict[Hashable, str] | None = ...,
178+
convert_dates: dict[HashableT, StataDateFormat] | None = ...,
178179
write_index: bool = ...,
179180
byteorder: str | None = ...,
180181
time_stamp: datetime.datetime | None = ...,
181182
data_label: str | None = ...,
182-
variable_labels: dict[Hashable, str] | None = ...,
183+
variable_labels: dict[HashableT, str] | None = ...,
183184
convert_strl: Sequence[Hashable] | None = ...,
184-
version: int | None = ...,
185+
version: Literal[118, 119] | None = ...,
185186
compression: CompressionOptions = ...,
186187
storage_options: StorageOptions = ...,
187188
*,
188-
value_labels: dict[Hashable, dict[float, str]] | None = ...,
189+
value_labels: dict[HashableT, dict[float, str]] | None = ...,
189190
) -> None: ...

0 commit comments

Comments
 (0)