@@ -351,23 +351,8 @@ def _convert_listlike_datetimes(
351351 yearfirst parsing behavior from to_datetime
352352 exact : bool, default True
353353 exact format matching behavior from to_datetime
354-
355- /// INSERT DOCUMENTATION UPDATE HERE ///
356- ########################
357- ########################
358- ########################
359- ########################
360- ########################
361- ########################
362- ########################
363- ########################
364- ########################
365- ########################
366- ########################
367- ########################
368- ########################
369- ########################
370- ########################
354+ threshold : float
355+ Minimum fraction of valid datetime components required
371356
372357 Returns
373358 -------
@@ -660,6 +645,7 @@ def to_datetime(
660645 unit : str | None = ...,
661646 origin = ...,
662647 cache : bool = ...,
648+ threshold : float = ...,
663649) -> Timestamp : ...
664650
665651
@@ -675,6 +661,7 @@ def to_datetime(
675661 unit : str | None = ...,
676662 origin = ...,
677663 cache : bool = ...,
664+ threshold : float = ...,
678665) -> Series : ...
679666
680667
@@ -690,6 +677,7 @@ def to_datetime(
690677 unit : str | None = ...,
691678 origin = ...,
692679 cache : bool = ...,
680+ threshold : float = ...,
693681) -> DatetimeIndex : ...
694682
695683
@@ -814,24 +802,19 @@ def to_datetime(
814802 is only used when there are at least 50 values. The presence of
815803 out-of-bounds values will render the cache unusable and may slow down
816804 parsing.
817-
818- /// INSERT DOCUMENTATION UPDATE HERE ///
819- ########################
820- ########################
821- ########################
822- ########################
823- ########################
824- ########################
825- ########################
826- ########################
827- ########################
828- ########################
829- ########################
830- ########################
831- ########################
832- ########################
833- ########################
834-
805+ threshold : float
806+ Minimum fraction of valid datetime components required to consider parsing
807+ successful. Components include year, month, day, hour, minute, and second
808+ if present in the input. An invalid component has too many or too few digits
809+ or a number outside the possible range (e.g., month outside [1, 12]). Behavior
810+ depends on the threshold:
811+
812+ - 1.0 (default): all components must be valid, else raises error (unless
813+ ``errors='coerce'``).
814+ - 0.0: any invalid component produces NaT, else returns a valid datetime.
815+ - Values between 0 and 1: if all components are valid, returns a valid
816+ datetime; if the fraction of valid components >= threshold, returns NaT;
817+ otherwise raises error.
835818 Returns
836819 -------
837820 datetime
@@ -1032,6 +1015,14 @@ def to_datetime(
10321015 >>> pd.to_datetime(["2018-10-26 12:00", datetime(2020, 1, 1, 18)], utc=True)
10331016 DatetimeIndex(['2018-10-26 12:00:00+00:00', '2020-01-01 18:00:00+00:00'],
10341017 dtype='datetime64[us, UTC]', freq=None)
1018+
1019+ - Input string with one invalid component returns NaT if threshold allows
1020+ partial validity
1021+
1022+ >>> pd.to_datetime(
1023+ ... "2018-100-26 12:00:00", format="%Y-%m-%d %H:%M:%S", threshold=0.5
1024+ ... )
1025+ NaT
10351026 """
10361027 if exact is not lib .no_default and format in {"mixed" , "ISO8601" }:
10371028 raise ValueError ("Cannot use 'exact' when 'format' is 'mixed' or 'ISO8601'" )
0 commit comments