File tree 2 files changed +20
-5
lines changed
2 files changed +20
-5
lines changed Original file line number Diff line number Diff line change @@ -766,9 +766,11 @@ def _getitem_lowerdim(self, tup: Tuple):
766
766
# ...but iloc should handle the tuple as simple integer-location
767
767
# instead of checking it as multiindex representation (GH 13797)
768
768
if isinstance (ax0 , ABCMultiIndex ) and self .name != "iloc" :
769
- result = self . _handle_lowerdim_multi_index_axis0 ( tup )
770
- if result is not None :
769
+ try :
770
+ result = self . _handle_lowerdim_multi_index_axis0 ( tup )
771
771
return result
772
+ except Exception :
773
+ pass
772
774
773
775
if len (tup ) > self .ndim :
774
776
raise IndexingError ("Too many indexers. handle elsewhere" )
@@ -816,9 +818,11 @@ def _getitem_nested_tuple(self, tup: Tuple):
816
818
if self .name != "loc" :
817
819
# This should never be reached, but lets be explicit about it
818
820
raise ValueError ("Too many indices" )
819
- result = self . _handle_lowerdim_multi_index_axis0 ( tup )
820
- if result is not None :
821
+ try :
822
+ result = self . _handle_lowerdim_multi_index_axis0 ( tup )
821
823
return result
824
+ except Exception :
825
+ pass
822
826
823
827
# this is a series with a multi-index specified a tuple of
824
828
# selectors
@@ -1065,7 +1069,7 @@ def _handle_lowerdim_multi_index_axis0(self, tup: Tuple):
1065
1069
if len (tup ) <= self .obj .index .nlevels and len (tup ) > self .ndim :
1066
1070
raise ek
1067
1071
1068
- return None
1072
+ raise Exception ( "No label returned" )
1069
1073
1070
1074
def _getitem_axis (self , key , axis : int ):
1071
1075
key = item_from_zerodim (key )
Original file line number Diff line number Diff line change @@ -853,6 +853,17 @@ def test_setitem_slice_into_readonly_backing_data():
853
853
assert not array .any ()
854
854
855
855
856
+ def test_access_none_value_in_multiindex ():
857
+ # GH34318: test that you can access a None value using .loc through a Multiindex
858
+
859
+ expected = None
860
+ result = pd .Series ([None ], pd .MultiIndex .from_arrays ([["Level1" ], ["Level2" ]])).loc [
861
+ ("Level1" , "Level2" )
862
+ ]
863
+
864
+ assert expected == result
865
+
866
+
856
867
"""
857
868
miscellaneous methods
858
869
"""
You can’t perform that action at this time.
0 commit comments