1010
1111try :
1212 import uncertainties .unumpy as unp
13- from uncertainties import ufloat , UFloat # noqa: F401
13+ from uncertainties import ufloat , UFloat
14+ from uncertainties .core import AffineScalarFunc # noqa: F401
15+
16+ def AffineScalarFunc__hash__ (self ):
17+ if not self ._linear_part .expanded ():
18+ self ._linear_part .expand ()
19+ combo = tuple (iter (self ._linear_part .linear_combo .items ()))
20+ if len (combo ) > 1 or combo [0 ][1 ] != 1.0 :
21+ return hash (combo )
22+ # The unique value that comes from a unique variable (which it also hashes to)
23+ return id (combo [0 ][0 ])
24+
25+ AffineScalarFunc .__hash__ = AffineScalarFunc__hash__
1426
15- HAS_UNCERTAINTIES = True
1627 _ufloat_nan = ufloat (np .nan , 0 )
28+ HAS_UNCERTAINTIES = True
1729except ImportError :
1830 unp = np
1931 HAS_UNCERTAINTIES = False
@@ -170,8 +182,8 @@ def dtype():
170182
171183
172184_base_numeric_dtypes = [float , int ]
173- _all_numeric_dtypes = (
174- _base_numeric_dtypes + [] if HAS_UNCERTAINTIES else [np .complex128 ]
185+ _all_numeric_dtypes = _base_numeric_dtypes + (
186+ [] if HAS_UNCERTAINTIES else [np .complex128 ]
175187)
176188
177189
@@ -650,23 +662,9 @@ def _get_exception(self, data, op_name):
650662 if op_name in ["__floordiv__" , "__rfloordiv__" , "__mod__" , "__rmod__" ]:
651663 return op_name , TypeError
652664 if op_name in ["__pow__" , "__rpow__" ]:
653- return DimensionalityError
654- complex128_dtype = pd .core .dtypes .dtypes .NumpyEADtype ("complex128" )
655- if (
656- (isinstance (obj , pd .Series ) and obj .dtype == complex128_dtype )
657- or (
658- isinstance (obj , pd .DataFrame )
659- and any ([dtype == complex128_dtype for dtype in obj .dtypes ])
660- )
661- or (isinstance (other , pd .Series ) and other .dtype == complex128_dtype )
662- or (
663- isinstance (other , pd .DataFrame )
664- and any ([dtype == complex128_dtype for dtype in other .dtypes ])
665- )
666- ):
667- if op_name in ["__floordiv__" , "__rfloordiv__" , "__mod__" , "__rmod__" ]:
668- return TypeError
669- return super ()._get_expected_exception (op_name , obj , other )
665+ return op_name , DimensionalityError
666+
667+ return op_name , None
670668
671669 # With Pint 0.21, series and scalar need to have compatible units for
672670 # the arithmetic to work
@@ -717,7 +715,9 @@ def test_divmod(self, data, USE_UNCERTAINTIES):
717715 self ._check_divmod_op (1 * ureg .Mm , ops .rdivmod , ser )
718716
719717 @pytest .mark .parametrize ("numeric_dtype" , _base_numeric_dtypes , indirect = True )
720- def test_divmod_series_array (self , data , data_for_twos ):
718+ def test_divmod_series_array (self , data , data_for_twos , USE_UNCERTAINTIES ):
719+ if USE_UNCERTAINTIES :
720+ pytest .skip (reason = "uncertainties does not implement divmod" )
721721 ser = pd .Series (data )
722722 self ._check_divmod_op (ser , divmod , data )
723723
@@ -727,12 +727,6 @@ def test_divmod_series_array(self, data, data_for_twos):
727727 other = pd .Series (other )
728728 self ._check_divmod_op (other , ops .rdivmod , ser )
729729
730- @pytest .mark .parametrize ("numeric_dtype" , _base_numeric_dtypes , indirect = True )
731- def test_divmod_series_array (self , data , data_for_twos , USE_UNCERTAINTIES ):
732- if USE_UNCERTAINTIES :
733- pytest .skip (reason = "uncertainties does not implement divmod" )
734- super ().test_divmod_series_array (data , data_for_twos )
735-
736730
737731class TestComparisonOps (base .BaseComparisonOpsTests ):
738732 def _compare_other (self , s , data , op_name , other ):
@@ -871,16 +865,6 @@ def test_reduce_series(
871865 warnings .simplefilter ("ignore" , RuntimeWarning )
872866 self .check_reduce (s , op_name , skipna )
873867
874- @pytest .mark .parametrize ("skipna" , [True , False ])
875- def test_reduce_series_xx (self , data , all_numeric_reductions , skipna ):
876- op_name = all_numeric_reductions
877- s = pd .Series (data )
878-
879- # min/max with empty produce numpy warnings
880- with warnings .catch_warnings ():
881- warnings .simplefilter ("ignore" , RuntimeWarning )
882- self .check_reduce (s , op_name , skipna )
883-
884868
885869class TestBooleanReduce (base .BaseBooleanReduceTests ):
886870 def check_reduce (self , s , op_name , skipna ):
@@ -922,7 +906,18 @@ class TestSetitem(base.BaseSetitemTests):
922906 @pytest .mark .parametrize ("numeric_dtype" , _base_numeric_dtypes , indirect = True )
923907 def test_setitem_scalar_key_sequence_raise (self , data ):
924908 # This can be removed when https://github.com/pandas-dev/pandas/pull/54441 is accepted
925- base .BaseSetitemTests .test_setitem_scalar_key_sequence_raise (self , data )
909+ arr = data [:5 ].copy ()
910+ with pytest .raises ((ValueError , TypeError )):
911+ arr [0 ] = arr [[0 , 1 ]]
912+
913+ def test_setitem_invalid (self , data , invalid_scalar ):
914+ # This can be removed when https://github.com/pandas-dev/pandas/pull/54441 is accepted
915+ msg = "" # messages vary by subclass, so we do not test it
916+ with pytest .raises ((ValueError , TypeError ), match = msg ):
917+ data [0 ] = invalid_scalar
918+
919+ with pytest .raises ((ValueError , TypeError ), match = msg ):
920+ data [:] = invalid_scalar
926921
927922 @pytest .mark .parametrize ("numeric_dtype" , _base_numeric_dtypes , indirect = True )
928923 def test_setitem_2d_values (self , data ):
0 commit comments