From f8f423078e12537f33ff17bb7fdd00091818fc20 Mon Sep 17 00:00:00 2001 From: Kernc Date: Sun, 14 Aug 2016 15:53:29 +0200 Subject: [PATCH 1/2] DOC: tm.assert_series_equal() fix docstring default values --- pandas/util/testing.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/util/testing.py b/pandas/util/testing.py index 2d1d88b69941b..94de8cb034024 100644 --- a/pandas/util/testing.py +++ b/pandas/util/testing.py @@ -1104,10 +1104,10 @@ def assert_series_equal(left, right, check_dtype=True, right : Series check_dtype : bool, default True Whether to check the Series dtype is identical. - check_index_type : bool / string {'equiv'}, default False + check_index_type : bool / string {'equiv'}, default 'equiv' Whether to check the Index class, dtype and inferred_type are identical. - check_series_type : bool, default False + check_series_type : bool, default True Whether to check the Series class is identical. check_less_precise : bool or int, default False Specify comparison precision. Only used when check_exact is False. From 9aaac80e85b797083b39348a245deafd2c782d80 Mon Sep 17 00:00:00 2001 From: Kernc Date: Fri, 12 Aug 2016 20:55:28 +0200 Subject: [PATCH 2/2] BUG: yield correct Series subclass in df.iterrows() (#13977) --- doc/source/whatsnew/v0.19.0.txt | 2 ++ pandas/core/frame.py | 3 ++- pandas/tests/frame/test_subclass.py | 7 +++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.19.0.txt b/doc/source/whatsnew/v0.19.0.txt index d7fe44e046d8e..e9a5534dac665 100644 --- a/doc/source/whatsnew/v0.19.0.txt +++ b/doc/source/whatsnew/v0.19.0.txt @@ -1097,3 +1097,5 @@ Bug Fixes - Bug in ``.to_string()`` when called with an integer ``line_width`` and ``index=False`` raises an UnboundLocalError exception because ``idx`` referenced before assignment. - Bug in ``read_csv()``, where aliases for utf-xx (e.g. UTF-xx, UTF_xx, utf_xx) raised UnicodeDecodeError (:issue:`13549`) + +- Bug in ``DataFrame.iterrows()`` not yielding proper ``Series`` subclasses (:issue:`13898`) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 501f4e443b1fc..205af5c805877 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -694,8 +694,9 @@ def iterrows(self): """ columns = self.columns + klass = self._constructor_sliced for k, v in zip(self.index, self.values): - s = Series(v, index=columns, name=k) + s = klass(v, index=columns, name=k) yield k, s def itertuples(self, index=True, name="Pandas"): diff --git a/pandas/tests/frame/test_subclass.py b/pandas/tests/frame/test_subclass.py index 0e0ee75a30c84..6a57f67a6cb3d 100644 --- a/pandas/tests/frame/test_subclass.py +++ b/pandas/tests/frame/test_subclass.py @@ -211,6 +211,13 @@ def test_subclass_align_combinations(self): tm.assertIsInstance(res2, tm.SubclassedDataFrame) tm.assert_frame_equal(res2, exp1) + def test_subclass_iterrows(self): + # GH 13977 + df = tm.SubclassedDataFrame({'a': [1]}) + for i, row in df.iterrows(): + tm.assertIsInstance(row, tm.SubclassedSeries) + tm.assert_series_equal(row, df.loc[i]) + def test_subclass_sparse_slice(self): rows = [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]] ssdf = tm.SubclassedSparseDataFrame(rows)