From 12ce2a0e785e84f5e7494ca173ef52ebb3d32ac8 Mon Sep 17 00:00:00 2001 From: Marc Garcia Date: Sun, 17 May 2020 23:09:26 +0100 Subject: [PATCH 1/2] DOC: Improve docstring of Series/DataFrame.bool --- pandas/core/generic.py | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 85b6a8431617a..dad7f1faac785 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -1375,16 +1375,36 @@ def __nonzero__(self): def bool(self): """ - Return the bool of a single element PandasObject. + Return the bool of a single element Series or DataFrame. - This must be a boolean scalar value, either True or False. Raise a - ValueError if the PandasObject does not have exactly 1 element, or that - element is not boolean + This must be a boolean scalar value, either True or False. It will raise a + ValueError if the Series or DataFrame does not have exactly 1 element, or that + element is not boolean (integer values 0 and 1 will also raise an exception). Returns ------- bool - Same single boolean value converted to bool type. + The value in the Series or DataFrame. + + See Also + -------- + Series.astype : Change the data type of a Series, including to boolean. + DataFrame.astype : Change the data type of a DataFrame, including to boolean. + numpy.bool : NumPy boolean data type, used by pandaas for boolean values. + + Examples + -------- + The method will only work for single element objects with a boolean value: + + >>> pd.Series([True]).bool() + True + >>> pd.Series([False]).bool() + False + + >>> pd.DataFrame({'col': [True]}).bool() + True + >>> pd.DataFrame({'col': [False]}).bool() + False """ v = self.squeeze() if isinstance(v, (bool, np.bool_)): From c76857a56955c7355119cd8dbd6a9915a7764cee Mon Sep 17 00:00:00 2001 From: Marc Garcia Date: Sun, 21 Jun 2020 12:19:30 +0100 Subject: [PATCH 2/2] Fixing typos --- pandas/core/generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index a725a9fd40fd3..bb2810ba7857f 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -1387,7 +1387,7 @@ def bool(self): -------- Series.astype : Change the data type of a Series, including to boolean. DataFrame.astype : Change the data type of a DataFrame, including to boolean. - numpy.bool : NumPy boolean data type, used by pandaas for boolean values. + numpy.bool_ : NumPy boolean data type, used by pandas for boolean values. Examples --------