@@ -1479,53 +1479,6 @@ def __nonzero__(self):
14791479
14801480 __bool__ = __nonzero__
14811481
1482- # Place this at the end of the file definition so it doesn't conflict
1483- # with builtins.bool in type annotations.
1484- @final
1485- def bool (self ):
1486- """
1487- Return the bool of a single element Series or DataFrame.
1488-
1489- This must be a boolean scalar value, either True or False. It will raise a
1490- ValueError if the Series or DataFrame does not have exactly 1 element, or that
1491- element is not boolean (integer values 0 and 1 will also raise an exception).
1492-
1493- Returns
1494- -------
1495- bool
1496- The value in the Series or DataFrame.
1497-
1498- See Also
1499- --------
1500- Series.astype : Change the data type of a Series, including to boolean.
1501- DataFrame.astype : Change the data type of a DataFrame, including to boolean.
1502- numpy.bool_ : NumPy boolean data type, used by pandas for boolean values.
1503-
1504- Examples
1505- --------
1506- The method will only work for single element objects with a boolean value:
1507-
1508- >>> pd.Series([True]).bool()
1509- True
1510- >>> pd.Series([False]).bool()
1511- False
1512-
1513- >>> pd.DataFrame({'col': [True]}).bool()
1514- True
1515- >>> pd.DataFrame({'col': [False]}).bool()
1516- False
1517- """
1518- v = self .squeeze ()
1519- if isinstance (v , (bool , np .bool_ )):
1520- return bool (v )
1521- elif is_scalar (v ):
1522- raise ValueError (
1523- "bool cannot act on a non-boolean single element "
1524- f"{ type (self ).__name__ } "
1525- )
1526-
1527- self .__nonzero__ ()
1528-
15291482 @final
15301483 def __abs__ (self : FrameOrSeries ) -> FrameOrSeries :
15311484 return self .abs ()
@@ -11104,6 +11057,53 @@ def first_valid_index(self):
1110411057 def last_valid_index (self ):
1110511058 return self ._find_valid_index ("last" )
1110611059
11060+ # Place this at the end of the class definition so it doesn't conflict
11061+ # with builtins.bool in type annotations.
11062+ @final
11063+ def bool (self ):
11064+ """
11065+ Return the bool of a single element Series or DataFrame.
11066+
11067+ This must be a boolean scalar value, either True or False. It will raise a
11068+ ValueError if the Series or DataFrame does not have exactly 1 element, or that
11069+ element is not boolean (integer values 0 and 1 will also raise an exception).
11070+
11071+ Returns
11072+ -------
11073+ bool
11074+ The value in the Series or DataFrame.
11075+
11076+ See Also
11077+ --------
11078+ Series.astype : Change the data type of a Series, including to boolean.
11079+ DataFrame.astype : Change the data type of a DataFrame, including to boolean.
11080+ numpy.bool_ : NumPy boolean data type, used by pandas for boolean values.
11081+
11082+ Examples
11083+ --------
11084+ The method will only work for single element objects with a boolean value:
11085+
11086+ >>> pd.Series([True]).bool()
11087+ True
11088+ >>> pd.Series([False]).bool()
11089+ False
11090+
11091+ >>> pd.DataFrame({'col': [True]}).bool()
11092+ True
11093+ >>> pd.DataFrame({'col': [False]}).bool()
11094+ False
11095+ """
11096+ v = self .squeeze ()
11097+ if isinstance (v , (bool , np .bool_ )):
11098+ return bool (v )
11099+ elif is_scalar (v ):
11100+ raise ValueError (
11101+ "bool cannot act on a non-boolean single element "
11102+ f"{ type (self ).__name__ } "
11103+ )
11104+
11105+ self .__nonzero__ ()
11106+
1110711107
1110811108def _doc_params (cls ):
1110911109 """Return a tuple of the doc params."""
0 commit comments