Skip to content

Commit ba353a5

Browse files
committed
TYP: move IndexLabel to pandas._typing
This eliminates repetition of the type annotations for index label in multiple places.
1 parent 1e35f87 commit ba353a5

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

pandas/_typing.py

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
List,
1616
Mapping,
1717
Optional,
18+
Sequence,
1819
Type,
1920
TypeVar,
2021
Union,
@@ -82,6 +83,7 @@
8283

8384
Axis = Union[str, int]
8485
Label = Optional[Hashable]
86+
IndexLabel = Optional[Union[bool, str, Sequence[Label]]]
8587
Level = Union[Label, int]
8688
Ordered = Optional[bool]
8789
JSONSerializable = Optional[Union[PythonScalar, List, Dict]]

pandas/core/generic.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
CompressionOptions,
4141
FilePathOrBuffer,
4242
FrameOrSeries,
43+
IndexLabel,
4344
JSONSerializable,
4445
Label,
4546
Level,
@@ -3160,7 +3161,7 @@ def to_csv(
31603161
columns: Optional[Sequence[Label]] = None,
31613162
header: Union[bool_t, List[str]] = True,
31623163
index: bool_t = True,
3163-
index_label: Optional[Union[bool_t, str, Sequence[Label]]] = None,
3164+
index_label: IndexLabel = None,
31643165
mode: str = "w",
31653166
encoding: Optional[str] = None,
31663167
compression: CompressionOptions = "infer",

pandas/io/formats/csvs.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@
1111
import numpy as np
1212

1313
from pandas._libs import writers as libwriters
14-
from pandas._typing import CompressionOptions, FilePathOrBuffer, Label, StorageOptions
14+
from pandas._typing import (
15+
CompressionOptions,
16+
FilePathOrBuffer,
17+
IndexLabel,
18+
StorageOptions,
19+
)
1520

1621
from pandas.core.dtypes.generic import (
1722
ABCDatetimeIndex,
@@ -30,8 +35,6 @@
3035
infer_compression,
3136
)
3237

33-
IndexLabel = Optional[Union[bool, str, Sequence[Label]]]
34-
3538

3639
class CSVFormatter:
3740
def __init__(

0 commit comments

Comments
 (0)