From 38b11b56036e984ffdb00a1d5a6c91a7362e9cb5 Mon Sep 17 00:00:00 2001 From: Sathvik Mulukutla Date: Sun, 20 Aug 2023 19:32:27 +0530 Subject: [PATCH 1/9] Updated map method documentation Added an example for standard functions for the map function --- pandas/core/frame.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 25fc5bd6664f5..34d18803c362c 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -10085,6 +10085,20 @@ def map( 0 3 4 1 5 5 + >>> def foo(x): + if x > 2.5: + x = 2 + + elif x <= 2.5: + x = 1 + + return x + + >>> df.map(foo) + 0 1 + 0 1 1 + 1 2 2 + Like Series.map, NA values can be ignored: >>> df_copy = df.copy() From 6f40da17ba224c7a7f634a34c22beb166f8bb300 Mon Sep 17 00:00:00 2001 From: Sathvik Mulukutla Date: Sun, 20 Aug 2023 20:05:48 +0530 Subject: [PATCH 2/9] Updated Documentation for the map method Added documentation for extra keyword arguments in the map method --- pandas/core/frame.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 34d18803c362c..c7cd2fba9582d 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -10085,16 +10085,16 @@ def map( 0 3 4 1 5 5 - >>> def foo(x): - if x > 2.5: + >>> def func(x,y): # x refers to the element in the DataFrame + if x > y: x = 2 - elif x <= 2.5: + elif x <= y: x = 1 return x - >>> df.map(foo) + >>> df.map(func, y=2.5) 0 1 0 1 1 1 2 2 From db413952d64fb9ea1d0871b358fd02c105cf4578 Mon Sep 17 00:00:00 2001 From: Sathvik Mulukutla Date: Wed, 30 Aug 2023 22:20:12 +0530 Subject: [PATCH 3/9] Modified initial docstring commit Used round function instead of defining a function in the example --- pandas/core/frame.py | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index c7cd2fba9582d..09a6fc3e77396 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -10084,20 +10084,11 @@ def map( 0 1 0 3 4 1 5 5 - - >>> def func(x,y): # x refers to the element in the DataFrame - if x > y: - x = 2 - - elif x <= y: - x = 1 - - return x - >>> df.map(func, y=2.5) - 0 1 - 0 1 1 - 1 2 2 + >>> df.map(round, digits=2) + 0 1 + 0 1.00 2.12 + 1 3.36 4.57 Like Series.map, NA values can be ignored: From dc6ee03555f4085368ef0a298c25bc51871e558e Mon Sep 17 00:00:00 2001 From: Sathvik Mulukutla <72032381+DarthKitten2130@users.noreply.github.com> Date: Wed, 6 Dec 2023 11:10:35 +0530 Subject: [PATCH 4/9] Replaced ValueError exception with TypeError exception in df.where function Replaced ValueError exception with TypeError as it is more appropriate for the error it serves --- pandas/core/generic.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 90946b8d9b5f4..1ad33f4cfc26b 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -10683,11 +10683,11 @@ def _where( if not isinstance(cond, ABCDataFrame): # This is a single-dimensional object. if not is_bool_dtype(cond): - raise ValueError(msg.format(dtype=cond.dtype)) + raise TypeError(msg.format(dtype=cond.dtype)) else: for _dt in cond.dtypes: if not is_bool_dtype(_dt): - raise ValueError(msg.format(dtype=_dt)) + raise TypeError(msg.format(dtype=_dt)) if cond._mgr.any_extension_types: # GH51574: avoid object ndarray conversion later on cond = cond._constructor( From 1d0fd4b4b60d0a420a334b19b002e0b1d3ef87a2 Mon Sep 17 00:00:00 2001 From: Sathvik Mulukutla <72032381+DarthKitten2130@users.noreply.github.com> Date: Thu, 14 Dec 2023 12:37:07 +0530 Subject: [PATCH 5/9] Updated test_where.py to account for updated exceptions --- pandas/tests/frame/indexing/test_where.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/frame/indexing/test_where.py b/pandas/tests/frame/indexing/test_where.py index 3d36d0471f02f..7a66b247ebcaa 100644 --- a/pandas/tests/frame/indexing/test_where.py +++ b/pandas/tests/frame/indexing/test_where.py @@ -250,7 +250,7 @@ def test_where_invalid_input_single(self, cond): df = DataFrame({"a": [1, 2, 3]}) msg = "Boolean array expected for the condition" - with pytest.raises(ValueError, match=msg): + with pytest.raises(TypeError, match=msg): df.where(cond) @pytest.mark.parametrize( @@ -272,7 +272,7 @@ def test_where_invalid_input_multiple(self, cond): df = DataFrame({"a": [1, 2, 3], "b": [2, 2, 2]}) msg = "Boolean array expected for the condition" - with pytest.raises(ValueError, match=msg): + with pytest.raises(TypeError, match=msg): df.where(cond) def test_where_dataframe_col_match(self): From fa010c58708f757d4be654f7fc3543ff683fc89f Mon Sep 17 00:00:00 2001 From: Sathvik Mulukutla <72032381+DarthKitten2130@users.noreply.github.com> Date: Thu, 14 Dec 2023 13:16:24 +0530 Subject: [PATCH 6/9] Update test_indexing.py to account for modified exceptions --- pandas/tests/frame/indexing/test_indexing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/frame/indexing/test_indexing.py b/pandas/tests/frame/indexing/test_indexing.py index 4be5be77b015c..929814cc8c03c 100644 --- a/pandas/tests/frame/indexing/test_indexing.py +++ b/pandas/tests/frame/indexing/test_indexing.py @@ -137,7 +137,7 @@ def test_getitem_boolean(self, mixed_float_frame, mixed_int_frame, datetime_fram subframe_obj = datetime_frame[indexer_obj] tm.assert_frame_equal(subframe_obj, subframe) - with pytest.raises(ValueError, match="Boolean array expected"): + with pytest.raises(TypeError, match="Boolean array expected"): datetime_frame[datetime_frame] # test that Series work From 84254bec7d9729bab2502594e725111772dff385 Mon Sep 17 00:00:00 2001 From: Sathvik Mulukutla Date: Thu, 14 Dec 2023 14:02:23 +0530 Subject: [PATCH 7/9] Revert "Updated test_where.py to account for updated exceptions" This reverts commit 1d0fd4b4b60d0a420a334b19b002e0b1d3ef87a2. --- pandas/tests/frame/indexing/test_where.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/frame/indexing/test_where.py b/pandas/tests/frame/indexing/test_where.py index 7a66b247ebcaa..3d36d0471f02f 100644 --- a/pandas/tests/frame/indexing/test_where.py +++ b/pandas/tests/frame/indexing/test_where.py @@ -250,7 +250,7 @@ def test_where_invalid_input_single(self, cond): df = DataFrame({"a": [1, 2, 3]}) msg = "Boolean array expected for the condition" - with pytest.raises(TypeError, match=msg): + with pytest.raises(ValueError, match=msg): df.where(cond) @pytest.mark.parametrize( @@ -272,7 +272,7 @@ def test_where_invalid_input_multiple(self, cond): df = DataFrame({"a": [1, 2, 3], "b": [2, 2, 2]}) msg = "Boolean array expected for the condition" - with pytest.raises(TypeError, match=msg): + with pytest.raises(ValueError, match=msg): df.where(cond) def test_where_dataframe_col_match(self): From 649f3a85d471f76bd92e74edb10c783d4bac0d8a Mon Sep 17 00:00:00 2001 From: Sathvik Mulukutla Date: Thu, 14 Dec 2023 16:46:53 +0530 Subject: [PATCH 8/9] Revert "Update test_indexing.py to account for modified exceptions" This reverts commit fa010c58708f757d4be654f7fc3543ff683fc89f. --- pandas/tests/frame/indexing/test_indexing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/frame/indexing/test_indexing.py b/pandas/tests/frame/indexing/test_indexing.py index 929814cc8c03c..4be5be77b015c 100644 --- a/pandas/tests/frame/indexing/test_indexing.py +++ b/pandas/tests/frame/indexing/test_indexing.py @@ -137,7 +137,7 @@ def test_getitem_boolean(self, mixed_float_frame, mixed_int_frame, datetime_fram subframe_obj = datetime_frame[indexer_obj] tm.assert_frame_equal(subframe_obj, subframe) - with pytest.raises(TypeError, match="Boolean array expected"): + with pytest.raises(ValueError, match="Boolean array expected"): datetime_frame[datetime_frame] # test that Series work From 3ad3653b8b5e0ab8c8ea9e6393efa5b847817754 Mon Sep 17 00:00:00 2001 From: Sathvik Mulukutla Date: Thu, 14 Dec 2023 17:00:05 +0530 Subject: [PATCH 9/9] bruh --- pandas/core/frame.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index c15ff444a10bc..4e61e9b24e720 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -10365,11 +10365,28 @@ def map( 0 1 0 3 4 1 5 5 +<<<<<<< HEAD >>> df.map(round, digits=2) 0 1 0 1.00 2.12 1 3.36 4.57 +======= + + >>> def foo(x): + if x > 2.5: + x = 2 + + elif x <= 2.5: + x = 1 + + return x + + >>> df.map(foo) + 0 1 + 0 1 1 + 1 2 2 +>>>>>>> parent of 6f40da17ba (Updated Documentation for the map method) Like Series.map, NA values can be ignored: