@@ -591,15 +591,6 @@ def _parsed_string_to_bounds(
591591 def _parse_with_reso (self , label : str ) -> tuple [Timestamp , Resolution ]:
592592 parsed , reso = super ()._parse_with_reso (label )
593593
594- # GH#58302 - Deprecate non-ISO string formats in .loc indexing
595- if isinstance (label , str ) and not _is_iso_format_string (label ):
596- msg = (
597- "Parsing non-ISO datetime strings in .loc is deprecated and will be "
598- "removed in a future version. Use ISO format (YYYY-MM-DD) instead. "
599- f"Got '{ label } '."
600- )
601- warnings .warn (msg , Pandas4Warning , stacklevel = find_stack_level ())
602-
603594 parsed = Timestamp (parsed )
604595
605596 if self .tz is not None and parsed .tzinfo is None :
@@ -645,6 +636,14 @@ def get_loc(self, key):
645636 parsed , reso = self ._parse_with_reso (key )
646637 except ValueError as err :
647638 raise KeyError (key ) from err
639+ # GH#58302 - Deprecate non-ISO string formats in .loc indexing
640+ if not _is_iso_format_string (key ):
641+ msg = (
642+ "Parsing non-ISO datetime strings in .loc is deprecated "
643+ "and will be removed in a future version. Use ISO format "
644+ f"(YYYY-MM-DD) instead. Got '{ key } '."
645+ )
646+ warnings .warn (msg , Pandas4Warning , stacklevel = find_stack_level ())
648647 self ._disallow_mismatched_indexing (parsed )
649648
650649 if self ._can_partial_date_slice (reso ):
0 commit comments