@@ -625,6 +625,17 @@ def check_date_format(self, *, date_type: str, date_value: str) -> bool:
625625 ### PANDAS TYPE PARSERS
626626 ###################################################################################################
627627
628+ def _date_is_isoformat (self , x : str ) -> bool :
629+ """
630+ Checks a string to see whether it can be coerced as an ISO-formatted date `YYYY-MM-DD`
631+ https://stackoverflow.com/a/61569783
632+ """
633+ try :
634+ datetime .fromisoformat (x .replace ('Z' , '+00:00' ))
635+ except (ValueError , TypeError ):
636+ return False
637+ return True
638+
628639 def _parse_dates (self , x : Union [None , str ], dayfirst : bool = True ) -> Union [pd .NaT , date .isoformat ]:
629640 """
630641 This is the hard-won 'trust nobody', certainly not Americans, date parser. This requires that the user
@@ -652,6 +663,9 @@ def _parse_dates(self, x: Union[None, str], dayfirst: bool = True) -> Union[pd.N
652663 if isinstance (x , str ) and len (x ) <= 10 and ":" in x :
653664 # This specific variation of a date is interpreted as a time, so ...
654665 x = re .sub (r"[\\/,\.:;]" , "-" , x )
666+ # Check if already in ISO Format
667+ if self ._date_is_isoformat (x ):
668+ return str (x ).strip ()[:10 ]
655669 # Check if to_datetime can handle things
656670 if not pd .isnull (pd .to_datetime (x , errors = "coerce" , dayfirst = dayfirst )):
657671 return date .isoformat (pd .to_datetime (x , errors = "coerce" , dayfirst = dayfirst ))
0 commit comments