10
10
11
11
try :
12
12
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__
14
26
15
- HAS_UNCERTAINTIES = True
16
27
_ufloat_nan = ufloat (np .nan , 0 )
28
+ HAS_UNCERTAINTIES = True
17
29
except ImportError :
18
30
unp = np
19
31
HAS_UNCERTAINTIES = False
@@ -170,8 +182,8 @@ def dtype():
170
182
171
183
172
184
_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 ]
175
187
)
176
188
177
189
@@ -650,23 +662,9 @@ def _get_exception(self, data, op_name):
650
662
if op_name in ["__floordiv__" , "__rfloordiv__" , "__mod__" , "__rmod__" ]:
651
663
return op_name , TypeError
652
664
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
670
668
671
669
# With Pint 0.21, series and scalar need to have compatible units for
672
670
# the arithmetic to work
@@ -717,7 +715,9 @@ def test_divmod(self, data, USE_UNCERTAINTIES):
717
715
self ._check_divmod_op (1 * ureg .Mm , ops .rdivmod , ser )
718
716
719
717
@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" )
721
721
ser = pd .Series (data )
722
722
self ._check_divmod_op (ser , divmod , data )
723
723
@@ -727,12 +727,6 @@ def test_divmod_series_array(self, data, data_for_twos):
727
727
other = pd .Series (other )
728
728
self ._check_divmod_op (other , ops .rdivmod , ser )
729
729
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
-
736
730
737
731
class TestComparisonOps (base .BaseComparisonOpsTests ):
738
732
def _compare_other (self , s , data , op_name , other ):
@@ -871,16 +865,6 @@ def test_reduce_series(
871
865
warnings .simplefilter ("ignore" , RuntimeWarning )
872
866
self .check_reduce (s , op_name , skipna )
873
867
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
-
884
868
885
869
class TestBooleanReduce (base .BaseBooleanReduceTests ):
886
870
def check_reduce (self , s , op_name , skipna ):
@@ -922,7 +906,18 @@ class TestSetitem(base.BaseSetitemTests):
922
906
@pytest .mark .parametrize ("numeric_dtype" , _base_numeric_dtypes , indirect = True )
923
907
def test_setitem_scalar_key_sequence_raise (self , data ):
924
908
# 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
926
921
927
922
@pytest .mark .parametrize ("numeric_dtype" , _base_numeric_dtypes , indirect = True )
928
923
def test_setitem_2d_values (self , data ):
0 commit comments