Skip to content

Commit bef9bae

Browse files
simonjayhawkinsTomAugspurger
authored andcommitted
TYPING : Series.name -> Optional[Hashable] (#29164)
* TYPING : Series.name -> Optional[Hashable]
1 parent 33c1b21 commit bef9bae

File tree

5 files changed

+14
-13
lines changed

5 files changed

+14
-13
lines changed

pandas/core/frame.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ def style(self):
871871
"""
872872

873873
@Appender(_shared_docs["items"])
874-
def items(self) -> Iterable[Tuple[Hashable, Series]]:
874+
def items(self) -> Iterable[Tuple[Optional[Hashable], Series]]:
875875
if self.columns.is_unique and hasattr(self, "_item_cache"):
876876
for k in self.columns:
877877
yield k, self._get_item_cache(k)

pandas/core/generic.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ class NDFrame(PandasObject, SelectionMixin):
194194
# TODO(PY36): replace with _attrs : Dict[Hashable, Any]
195195
# We need the TYPE_CHECKING, because _attrs is not a class attribute
196196
# and Py35 doesn't support the new syntax.
197-
_attrs = {} # type: Dict[Hashable, Any]
197+
_attrs = {} # type: Dict[Optional[Hashable], Any]
198198

199199
# ----------------------------------------------------------------------
200200
# Constructors
@@ -205,7 +205,7 @@ def __init__(
205205
axes: Optional[List[Index]] = None,
206206
copy: bool = False,
207207
dtype: Optional[Dtype] = None,
208-
attrs: Optional[Mapping[Hashable, Any]] = None,
208+
attrs: Optional[Mapping[Optional[Hashable], Any]] = None,
209209
fastpath: bool = False,
210210
):
211211

@@ -248,7 +248,7 @@ def _init_mgr(self, mgr, axes=None, dtype=None, copy=False):
248248
# ----------------------------------------------------------------------
249249

250250
@property
251-
def attrs(self) -> Dict[Hashable, Any]:
251+
def attrs(self) -> Dict[Optional[Hashable], Any]:
252252
"""
253253
Dictionary of global attributes on this object.
254254
"""
@@ -257,7 +257,7 @@ def attrs(self) -> Dict[Hashable, Any]:
257257
return self._attrs
258258

259259
@attrs.setter
260-
def attrs(self, value: Mapping[Hashable, Any]) -> None:
260+
def attrs(self, value: Mapping[Optional[Hashable], Any]) -> None:
261261
self._attrs = dict(value)
262262

263263
@property
@@ -3149,10 +3149,10 @@ def to_csv(
31493149
sep: str = ",",
31503150
na_rep: str = "",
31513151
float_format: Optional[str] = None,
3152-
columns: Optional[Sequence[Hashable]] = None,
3152+
columns: Optional[Sequence[Optional[Hashable]]] = None,
31533153
header: Union[bool_t, List[str]] = True,
31543154
index: bool_t = True,
3155-
index_label: Optional[Union[bool_t, str, Sequence[Hashable]]] = None,
3155+
index_label: Optional[Union[bool_t, str, Sequence[Optional[Hashable]]]] = None,
31563156
mode: str = "w",
31573157
encoding: Optional[str] = None,
31583158
compression: Optional[Union[str, Mapping[str, str]]] = "infer",

pandas/core/groupby/generic.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
FrozenSet,
1818
Hashable,
1919
Iterable,
20+
Optional,
2021
Sequence,
2122
Tuple,
2223
Type,
@@ -142,7 +143,7 @@ def pinner(cls):
142143
class SeriesGroupBy(GroupBy):
143144
_apply_whitelist = base.series_apply_whitelist
144145

145-
def _iterate_slices(self) -> Iterable[Tuple[Hashable, Series]]:
146+
def _iterate_slices(self) -> Iterable[Tuple[Optional[Hashable], Series]]:
146147
yield self._selection_name, self._selected_obj
147148

148149
@property
@@ -926,7 +927,7 @@ def aggregate(self, func=None, *args, **kwargs):
926927

927928
agg = aggregate
928929

929-
def _iterate_slices(self) -> Iterable[Tuple[Hashable, Series]]:
930+
def _iterate_slices(self) -> Iterable[Tuple[Optional[Hashable], Series]]:
930931
obj = self._selected_obj
931932
if self.axis == 1:
932933
obj = obj.T

pandas/core/groupby/groupby.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ def _python_apply_general(self, f):
745745
keys, values, not_indexed_same=mutated or self.mutated
746746
)
747747

748-
def _iterate_slices(self) -> Iterable[Tuple[Hashable, Series]]:
748+
def _iterate_slices(self) -> Iterable[Tuple[Optional[Hashable], Series]]:
749749
raise AbstractMethodError(self)
750750

751751
def transform(self, func, *args, **kwargs):

pandas/core/series.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from io import StringIO
66
from shutil import get_terminal_size
77
from textwrap import dedent
8-
from typing import Any, Callable, Hashable, List
8+
from typing import Any, Callable, Hashable, List, Optional
99
import warnings
1010

1111
import numpy as np
@@ -472,11 +472,11 @@ def dtypes(self):
472472
return self._data.dtype
473473

474474
@property
475-
def name(self) -> Hashable:
475+
def name(self) -> Optional[Hashable]:
476476
return self.attrs.get("name", None)
477477

478478
@name.setter
479-
def name(self, value: Hashable) -> None:
479+
def name(self, value: Optional[Hashable]) -> None:
480480
if not is_hashable(value):
481481
raise TypeError("Series.name must be a hashable type")
482482
self.attrs["name"] = value

0 commit comments

Comments
 (0)