7272 sanitize_array ,
7373)
7474from pandas .core .generic import NDFrame
75- from pandas .core .indexers import maybe_convert_indices
75+ from pandas .core .indexers import maybe_convert_indices , unpack_1tuple
7676from pandas .core .indexes .accessors import CombinedDatetimelikeProperties
7777from pandas .core .indexes .api import (
7878 Float64Index ,
@@ -851,6 +851,8 @@ def __getitem__(self, key):
851851 key_is_scalar = is_scalar (key )
852852 if key_is_scalar :
853853 key = self .index ._convert_scalar_indexer (key , kind = "getitem" )
854+ elif isinstance (key , (list , tuple )):
855+ key = unpack_1tuple (key )
854856
855857 if key_is_scalar or isinstance (self .index , MultiIndex ):
856858 # Otherwise index.get_value will raise InvalidIndexError
@@ -893,16 +895,7 @@ def _get_with(self, key):
893895 "supported, use the appropriate DataFrame column"
894896 )
895897 elif isinstance (key , tuple ):
896- try :
897- return self ._get_values_tuple (key )
898- except ValueError :
899- # if we don't have a MultiIndex, we may still be able to handle
900- # a 1-tuple. see test_1tuple_without_multiindex
901- if len (key ) == 1 :
902- key = key [0 ]
903- if isinstance (key , slice ):
904- return self ._get_values (key )
905- raise
898+ return self ._get_values_tuple (key )
906899
907900 if not isinstance (key , (list , np .ndarray , ExtensionArray , Series , Index )):
908901 key = list (key )
@@ -924,26 +917,8 @@ def _get_with(self, key):
924917 else :
925918 return self .iloc [key ]
926919
927- if isinstance (key , (list , tuple )):
928- # TODO: de-dup with tuple case handled above?
920+ if isinstance (key , list ):
929921 # handle the dup indexing case GH#4246
930- if len (key ) == 1 and isinstance (key [0 ], slice ):
931- # [slice(0, 5, None)] will break if you convert to ndarray,
932- # e.g. as requested by np.median
933- # FIXME: hack
934- if isinstance (key , list ):
935- # GH#31299
936- warnings .warn (
937- "Indexing with a single-item list containing a "
938- "slice is deprecated and will raise in a future "
939- "version. Pass a tuple instead." ,
940- FutureWarning ,
941- stacklevel = 3 ,
942- )
943- # TODO: use a message more like numpy's?
944- key = tuple (key )
945- return self ._get_values (key )
946-
947922 return self .loc [key ]
948923
949924 return self .reindex (key )
0 commit comments