33"""
44
55from __future__ import annotations
6-
6+ from pandas . _libs import lib
77from collections .abc import (
88 Callable ,
99 Hashable ,
@@ -6777,14 +6777,24 @@ def _flex_method(self, other, op, *, level=None, fill_value=None, axis: Axis = 0
67776777 if isinstance (other , Series ):
67786778 return self ._binop (other , op , level = level , fill_value = fill_value )
67796779 elif isinstance (other , (np .ndarray , list , tuple , ExtensionArray )):
6780+ if isinstance (other , np .ndarray ) and other .ndim == 0 :
6781+ scalar = lib .item_from_zerodim (other )
6782+
6783+ if fill_value is not None :
6784+ if isna (scalar ):
6785+ return op (self , fill_value )
6786+ self = self .fillna (fill_value )
6787+
6788+ return op (self , scalar )
6789+
67806790 if len (other ) != len (self ):
67816791 raise ValueError ("Lengths must be equal" )
67826792 other = self ._constructor (other , self .index , copy = False )
67836793 result = self ._binop (other , op , level = level , fill_value = fill_value )
67846794 result ._name = res_name
67856795 return result
6796+
67866797 elif isinstance (other , ABCDataFrame ):
6787- # GH#46179
67886798 raise TypeError (
67896799 f"Series.{ op .__name__ .strip ('_' )} does not support a DataFrame "
67906800 f"`other`. Use df.{ op .__name__ .strip ('_' )} (ser) instead."
@@ -6794,9 +6804,10 @@ def _flex_method(self, other, op, *, level=None, fill_value=None, axis: Axis = 0
67946804 if isna (other ):
67956805 return op (self , fill_value )
67966806 self = self .fillna (fill_value )
6797-
6807+
67986808 return op (self , other )
67996809
6810+
68006811 def eq (
68016812 self ,
68026813 other ,
0 commit comments