diff --git a/pandas/_typing.py b/pandas/_typing.py index 7aef5c02e290f..16d81c0d39cbe 100644 --- a/pandas/_typing.py +++ b/pandas/_typing.py @@ -83,7 +83,7 @@ Axis = Union[str, int] Label = Optional[Hashable] -IndexLabel = Optional[Union[Label, Sequence[Label]]] +IndexLabel = Union[Label, Sequence[Label]] Level = Union[Label, int] Ordered = Optional[bool] JSONSerializable = Optional[Union[PythonScalar, List, Dict]] diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 814f307749d50..cc18b8681200f 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -3154,7 +3154,7 @@ def to_csv( columns: Optional[Sequence[Label]] = None, header: Union[bool_t, List[str]] = True, index: bool_t = True, - index_label: IndexLabel = None, + index_label: Optional[IndexLabel] = None, mode: str = "w", encoding: Optional[str] = None, compression: CompressionOptions = "infer", diff --git a/pandas/io/formats/csvs.py b/pandas/io/formats/csvs.py index 1bda16d126905..51a3906692e03 100644 --- a/pandas/io/formats/csvs.py +++ b/pandas/io/formats/csvs.py @@ -42,7 +42,7 @@ def __init__( cols: Optional[Sequence[Label]] = None, header: Union[bool, Sequence[Hashable]] = True, index: bool = True, - index_label: IndexLabel = None, + index_label: Optional[IndexLabel] = None, mode: str = "w", encoding: Optional[str] = None, errors: str = "strict", @@ -100,7 +100,7 @@ def index_label(self) -> IndexLabel: return self._index_label @index_label.setter - def index_label(self, index_label: IndexLabel) -> None: + def index_label(self, index_label: Optional[IndexLabel]) -> None: if index_label is not False: if index_label is None: index_label = self._get_index_label_from_obj()