@@ -352,23 +352,8 @@ def _convert_listlike_datetimes(
352352 yearfirst parsing behavior from to_datetime
353353 exact : bool, default True
354354 exact format matching behavior from to_datetime
355-
356- /// INSERT DOCUMENTATION UPDATE HERE ///
357- ########################
358- ########################
359- ########################
360- ########################
361- ########################
362- ########################
363- ########################
364- ########################
365- ########################
366- ########################
367- ########################
368- ########################
369- ########################
370- ########################
371- ########################
355+ threshold : float
356+ Minimum fraction of valid datetime components required
372357
373358 Returns
374359 -------
@@ -664,6 +649,7 @@ def to_datetime(
664649 unit : str | None = ...,
665650 origin = ...,
666651 cache : bool = ...,
652+ threshold : float = ...,
667653) -> Timestamp : ...
668654
669655
@@ -679,6 +665,7 @@ def to_datetime(
679665 unit : str | None = ...,
680666 origin = ...,
681667 cache : bool = ...,
668+ threshold : float = ...,
682669) -> Series : ...
683670
684671
@@ -694,6 +681,7 @@ def to_datetime(
694681 unit : str | None = ...,
695682 origin = ...,
696683 cache : bool = ...,
684+ threshold : float = ...,
697685) -> DatetimeIndex : ...
698686
699687
@@ -818,24 +806,19 @@ def to_datetime(
818806 is only used when there are at least 50 values. The presence of
819807 out-of-bounds values will render the cache unusable and may slow down
820808 parsing.
821-
822- /// INSERT DOCUMENTATION UPDATE HERE ///
823- ########################
824- ########################
825- ########################
826- ########################
827- ########################
828- ########################
829- ########################
830- ########################
831- ########################
832- ########################
833- ########################
834- ########################
835- ########################
836- ########################
837- ########################
838-
809+ threshold : float
810+ Minimum fraction of valid datetime components required to consider parsing
811+ successful. Components include year, month, day, hour, minute, and second
812+ if present in the input. An invalid component has too many or too few digits
813+ or a number outside the possible range (e.g., month outside [1, 12]). Behavior
814+ depends on the threshold:
815+
816+ - 1.0 (default): all components must be valid, else raises error (unless
817+ ``errors='coerce'``).
818+ - 0.0: any invalid component produces NaT, else returns a valid datetime.
819+ - Values between 0 and 1: if all components are valid, returns a valid
820+ datetime; if the fraction of valid components >= threshold, returns NaT;
821+ otherwise raises error.
839822 Returns
840823 -------
841824 datetime
@@ -1036,6 +1019,14 @@ def to_datetime(
10361019 >>> pd.to_datetime(["2018-10-26 12:00", datetime(2020, 1, 1, 18)], utc=True)
10371020 DatetimeIndex(['2018-10-26 12:00:00+00:00', '2020-01-01 18:00:00+00:00'],
10381021 dtype='datetime64[us, UTC]', freq=None)
1022+
1023+ - Input string with one invalid component returns NaT if threshold allows
1024+ partial validity
1025+
1026+ >>> pd.to_datetime(
1027+ ... "2018-100-26 12:00:00", format="%Y-%m-%d %H:%M:%S", threshold=0.5
1028+ ... )
1029+ NaT
10391030 """
10401031 if exact is not lib .no_default and format in {"mixed" , "ISO8601" }:
10411032 raise ValueError ("Cannot use 'exact' when 'format' is 'mixed' or 'ISO8601'" )
0 commit comments