From 6b8f9cb26a54d9d58343987dab3e9287f2bbef45 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Sun, 30 Aug 2020 16:27:57 +0100 Subject: [PATCH 1/2] TYP: misc typing fixes for pandas\core\frame.py --- pandas/core/frame.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 95bd757f1994e..50db9fced6e73 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -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. @@ -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/848 + # error: namedtuple() expects a string literal as the first argument [misc] + itertuple = collections.namedtuple( # type: ignore + name, fields, rename=True + ) return map(itertuple._make, zip(*arrays)) # fallback to regular tuples @@ -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): From 4cdb0487e3861e153e154abd5e7b56839c1c207c Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Sun, 30 Aug 2020 18:16:22 +0100 Subject: [PATCH 2/2] correct issue number --- pandas/core/frame.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 50db9fced6e73..e14f757e02159 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -1088,9 +1088,9 @@ def itertuples(self, index: bool = True, name: Optional[str] = "Pandas"): arrays.extend(self.iloc[:, k] for k in range(len(self.columns))) if name is not None: - # https://github.com/python/mypy/issues/848 - # error: namedtuple() expects a string literal as the first argument [misc] - itertuple = collections.namedtuple( # type: ignore + # 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))