From 04179676d38821b772daa0a3b61874de6a49e6ae Mon Sep 17 00:00:00 2001 From: Achmad Fathoni Date: Tue, 19 Jul 2022 20:56:59 +0700 Subject: [PATCH 1/4] Add Tuple[slice] in iLocIndexerFrame. Fix #143 --- pandas-stubs/core/frame.pyi | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas-stubs/core/frame.pyi b/pandas-stubs/core/frame.pyi index 6264a0637..663c0fc26 100644 --- a/pandas-stubs/core/frame.pyi +++ b/pandas-stubs/core/frame.pyi @@ -99,6 +99,7 @@ class _iLocIndexerFrame(_iLocIndexer): IndexType, MaskType, Tuple[Union[IndexType, MaskType], Union[IndexType, MaskType]], + Tuple[slice], ], ) -> DataFrame: ... def __setitem__( From 496324b6d392b65f3658eb89942b0886e164af94 Mon Sep 17 00:00:00 2001 From: Achmad Fathoni Date: Wed, 3 Aug 2022 21:23:06 +0700 Subject: [PATCH 2/4] Add test for iloc[Tuple[slice]] --- tests/test_frame.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/test_frame.py b/tests/test_frame.py index 523bb7c1e..12899ecb8 100644 --- a/tests/test_frame.py +++ b/tests/test_frame.py @@ -1156,6 +1156,9 @@ def test_iloc_npint() -> None: iloc = np.argmin(np.random.standard_normal(3)) df.iloc[iloc] +def test_iloc_tuple() -> None: + df = pd.DataFrame({"Char": ["A", "B", "C"], "Number": [1, 2, 3]}) + df = df.iloc[0:2,] def test_set_columns() -> None: # GH 73 From e8b2f65f62d946b94c8627cad5723b75341944c1 Mon Sep 17 00:00:00 2001 From: Achmad Fathoni Date: Wed, 3 Aug 2022 21:44:37 +0700 Subject: [PATCH 3/4] Add comment & spacing --- tests/test_frame.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/test_frame.py b/tests/test_frame.py index 4a419c305..2a9cc77c6 100644 --- a/tests/test_frame.py +++ b/tests/test_frame.py @@ -1151,10 +1151,13 @@ def test_iloc_npint() -> None: iloc = np.argmin(np.random.standard_normal(3)) df.iloc[iloc] + +# https://github.com/pandas-dev/pandas-stubs/issues/143 def test_iloc_tuple() -> None: df = pd.DataFrame({"Char": ["A", "B", "C"], "Number": [1, 2, 3]}) df = df.iloc[0:2,] + def test_set_columns() -> None: # GH 73 df = pd.DataFrame({"a": [1, 2, 3], "b": [0.0, 1, 1]}) From 3391acae41d398a1a094e809427b8374b2ebd20a Mon Sep 17 00:00:00 2001 From: Achmad Fathoni Date: Thu, 4 Aug 2022 13:14:46 +0700 Subject: [PATCH 4/4] Fix style according to black standard --- pandas-stubs/core/frame.pyi | 5 ++++- tests/test_frame.py | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pandas-stubs/core/frame.pyi b/pandas-stubs/core/frame.pyi index 79b6fb0d0..482a2dcc3 100644 --- a/pandas-stubs/core/frame.pyi +++ b/pandas-stubs/core/frame.pyi @@ -89,7 +89,10 @@ class _iLocIndexerFrame(_iLocIndexer): @overload def __getitem__( self, - idx: IndexType | MaskType | tuple[IndexType | MaskType, IndexType | MaskType] | tuple[slice], + idx: IndexType + | MaskType + | tuple[IndexType | MaskType, IndexType | MaskType] + | tuple[slice], ) -> DataFrame: ... def __setitem__( self, diff --git a/tests/test_frame.py b/tests/test_frame.py index 2a9cc77c6..9bd211d70 100644 --- a/tests/test_frame.py +++ b/tests/test_frame.py @@ -1155,7 +1155,9 @@ def test_iloc_npint() -> None: # https://github.com/pandas-dev/pandas-stubs/issues/143 def test_iloc_tuple() -> None: df = pd.DataFrame({"Char": ["A", "B", "C"], "Number": [1, 2, 3]}) - df = df.iloc[0:2,] + df = df.iloc[ + 0:2, + ] def test_set_columns() -> None: