Skip to content

Commit

Permalink
TYP: misc typing fixes for pandas\core\frame.py (pandas-dev#35990)
Browse files Browse the repository at this point in the history
* TYP: misc typing fixes for pandas\core\frame.py

* correct issue number
  • Loading branch information
simonjayhawkins committed Aug 31, 2020
1 parent b45327f commit f46ebe8
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pandas/core/frame.py
Expand Up @@ -1014,7 +1014,7 @@ def iterrows(self) -> Iterable[Tuple[Label, Series]]:
s = klass(v, index=columns, name=k)
yield k, s

def itertuples(self, index=True, name="Pandas"):
def itertuples(self, index: bool = True, name: Optional[str] = "Pandas"):
"""
Iterate over DataFrame rows as namedtuples.
Expand Down Expand Up @@ -1088,7 +1088,11 @@ def itertuples(self, index=True, name="Pandas"):
arrays.extend(self.iloc[:, k] for k in range(len(self.columns)))

if name is not None:
itertuple = collections.namedtuple(name, fields, rename=True)
# https://github.com/python/mypy/issues/9046
# error: namedtuple() expects a string literal as the first argument
itertuple = collections.namedtuple( # type: ignore[misc]
name, fields, rename=True
)
return map(itertuple._make, zip(*arrays))

# fallback to regular tuples
Expand Down Expand Up @@ -4591,7 +4595,7 @@ def set_index(
frame = self.copy()

arrays = []
names = []
names: List[Label] = []
if append:
names = list(self.index.names)
if isinstance(self.index, MultiIndex):
Expand Down

0 comments on commit f46ebe8

Please sign in to comment.