From 7ca98411f02a282d46764449df7b896723db1f67 Mon Sep 17 00:00:00 2001 From: Sachin Yadav Date: Fri, 22 Aug 2025 17:53:26 +0530 Subject: [PATCH 1/7] DOC: Clarify note on date_range/timedelta_range arguments --- pandas/core/indexes/datetimes.py | 190 ++++++------------------------- 1 file changed, 35 insertions(+), 155 deletions(-) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index ce6ea1ed980dd..e9230a397706b 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -836,176 +836,56 @@ def date_range( """ Return a fixed frequency DatetimeIndex. - Returns the range of equally spaced time points (where the difference between any - two adjacent points is specified by the given frequency) such that they fall in the - range `[start, end]` , where the first one and the last one are, resp., the first - and last time points in that range that fall on the boundary of ``freq`` (if given - as a frequency string) or that are valid for ``freq`` (if given as a - :class:`pandas.tseries.offsets.DateOffset`). If ``freq`` is positive, the points - satisfy `start <[=] x <[=] end`, and if ``freq`` is negative, the points satisfy - `end <[=] x <[=] start`. (If exactly one of ``start``, ``end``, or ``freq`` is *not* - specified, this missing parameter can be computed given ``periods``, the number of - timesteps in the range. See the note below.) + :param start: Left bound for generating dates. Accepts string or datetime-like object. Optional. + :type start: str or datetime-like, optional - Parameters - ---------- - start : str or datetime-like, optional - Left bound for generating dates. - end : str or datetime-like, optional - Right bound for generating dates. - periods : int, optional - Number of periods to generate. - freq : str, Timedelta, datetime.timedelta, or DateOffset, default 'D' - Frequency strings can have multiples, e.g. '5h'. See - :ref:`here ` for a list of - frequency aliases. - tz : str or tzinfo, optional - Time zone name for returning localized DatetimeIndex, for example - 'Asia/Hong_Kong'. By default, the resulting DatetimeIndex is - timezone-naive unless timezone-aware datetime-likes are passed. - normalize : bool, default False - Normalize start/end dates to midnight before generating date range. - name : str, default None - Name of the resulting DatetimeIndex. - inclusive : {"both", "neither", "left", "right"}, default "both" - Include boundaries; Whether to set each bound as closed or open. + :param end: Right bound for generating dates. Accepts string or datetime-like object. Optional. + :type end: str or datetime-like, optional - .. versionadded:: 1.4.0 - unit : str, default None - Specify the desired resolution of the result. + :param periods: Number of periods to generate. Mutually exclusive with one of `start` or `end`. Optional. + :type periods: int, optional - .. versionadded:: 2.0.0 - **kwargs - For compatibility. Has no effect on the result. + :param freq: Frequency string or offset. Determines the spacing between dates. Defaults to 'D' (day) if not specified and enough information is provided. Accepts string (e.g., '5h'), Timedelta, datetime.timedelta, or DateOffset. + :type freq: str, Timedelta, datetime.timedelta, or DateOffset, optional - Returns - ------- - DatetimeIndex - A DatetimeIndex object of the generated dates. + :param tz: Time zone name or tzinfo to localize the DatetimeIndex. If not specified, the result is timezone-naive unless timezone-aware inputs are provided. + :type tz: str or tzinfo, optional - See Also - -------- - DatetimeIndex : An immutable container for datetimes. - timedelta_range : Return a fixed frequency TimedeltaIndex. - period_range : Return a fixed frequency PeriodIndex. - interval_range : Return a fixed frequency IntervalIndex. + :param normalize: Whether to normalize start/end dates to midnight before generating the date range. + :type normalize: bool, default False - Notes - ----- - Of the four parameters ``start``, ``end``, ``periods``, and ``freq``, - exactly three must be specified. If ``freq`` is omitted, the resulting - ``DatetimeIndex`` will have ``periods`` linearly spaced elements between - ``start`` and ``end`` (closed on both sides). + :param name: Name to assign to the resulting DatetimeIndex. + :type name: str, optional - To learn more about the frequency strings, please see - :ref:`this link`. + :param inclusive: Whether to include boundaries. One of {"both", "neither", "left", "right"}. Default is "both". + :type inclusive: {"both", "neither", "left", "right"}, default "both" - Examples - -------- - **Specifying the values** - - The next four examples generate the same `DatetimeIndex`, but vary - the combination of `start`, `end` and `periods`. - - Specify `start` and `end`, with the default daily frequency. - - >>> pd.date_range(start="1/1/2018", end="1/08/2018") - DatetimeIndex(['2018-01-01', '2018-01-02', '2018-01-03', '2018-01-04', - '2018-01-05', '2018-01-06', '2018-01-07', '2018-01-08'], - dtype='datetime64[ns]', freq='D') - - Specify timezone-aware `start` and `end`, with the default daily frequency. - - >>> pd.date_range( - ... start=pd.to_datetime("1/1/2018").tz_localize("Europe/Berlin"), - ... end=pd.to_datetime("1/08/2018").tz_localize("Europe/Berlin"), - ... ) - DatetimeIndex(['2018-01-01 00:00:00+01:00', '2018-01-02 00:00:00+01:00', - '2018-01-03 00:00:00+01:00', '2018-01-04 00:00:00+01:00', - '2018-01-05 00:00:00+01:00', '2018-01-06 00:00:00+01:00', - '2018-01-07 00:00:00+01:00', '2018-01-08 00:00:00+01:00'], - dtype='datetime64[ns, Europe/Berlin]', freq='D') - - Specify `start` and `periods`, the number of periods (days). - - >>> pd.date_range(start="1/1/2018", periods=8) - DatetimeIndex(['2018-01-01', '2018-01-02', '2018-01-03', '2018-01-04', - '2018-01-05', '2018-01-06', '2018-01-07', '2018-01-08'], - dtype='datetime64[ns]', freq='D') - - Specify `end` and `periods`, the number of periods (days). - - >>> pd.date_range(end="1/1/2018", periods=8) - DatetimeIndex(['2017-12-25', '2017-12-26', '2017-12-27', '2017-12-28', - '2017-12-29', '2017-12-30', '2017-12-31', '2018-01-01'], - dtype='datetime64[ns]', freq='D') - - Specify `start`, `end`, and `periods`; the frequency is generated - automatically (linearly spaced). + :param unit: Specify the desired resolution of the result (e.g., 's' for seconds). + :type unit: str, optional - >>> pd.date_range(start="2018-04-24", end="2018-04-27", periods=3) - DatetimeIndex(['2018-04-24 00:00:00', '2018-04-25 12:00:00', - '2018-04-27 00:00:00'], - dtype='datetime64[ns]', freq=None) + :param kwargs: Additional keyword arguments for compatibility. Has no effect on the result. - **Other Parameters** + :return: DatetimeIndex of the generated dates. + :rtype: DatetimeIndex - Changed the `freq` (frequency) to ``'ME'`` (month end frequency). + :raises ValueError: If less than three of the four parameters (`start`, `end`, `periods`, `freq`) are specified. - >>> pd.date_range(start="1/1/2018", periods=5, freq="ME") - DatetimeIndex(['2018-01-31', '2018-02-28', '2018-03-31', '2018-04-30', - '2018-05-31'], - dtype='datetime64[ns]', freq='ME') + .. note:: + Of the four parameters (`start`, `end`, `periods`, `freq`), exactly three must be specified. If `freq` is omitted, the resulting DatetimeIndex will have `periods` linearly spaced elements between `start` and `end` (inclusive or exclusive depending on `inclusive`). - Multiples are allowed + .. seealso:: + :class:`pandas.DatetimeIndex` : Immutable container for datetimes. + :func:`pandas.timedelta_range` : Return a fixed frequency TimedeltaIndex. + :func:`pandas.period_range` : Return a fixed frequency PeriodIndex. + :func:`pandas.interval_range` : Return a fixed frequency IntervalIndex. - >>> pd.date_range(start="1/1/2018", periods=5, freq="3ME") - DatetimeIndex(['2018-01-31', '2018-04-30', '2018-07-31', '2018-10-31', - '2019-01-31'], - dtype='datetime64[ns]', freq='3ME') - - `freq` can also be specified as an Offset object. - - >>> pd.date_range(start="1/1/2018", periods=5, freq=pd.offsets.MonthEnd(3)) - DatetimeIndex(['2018-01-31', '2018-04-30', '2018-07-31', '2018-10-31', - '2019-01-31'], - dtype='datetime64[ns]', freq='3ME') - - Specify `tz` to set the timezone. - - >>> pd.date_range(start="1/1/2018", periods=5, tz="Asia/Tokyo") - DatetimeIndex(['2018-01-01 00:00:00+09:00', '2018-01-02 00:00:00+09:00', - '2018-01-03 00:00:00+09:00', '2018-01-04 00:00:00+09:00', - '2018-01-05 00:00:00+09:00'], - dtype='datetime64[ns, Asia/Tokyo]', freq='D') - - `inclusive` controls whether to include `start` and `end` that are on the - boundary. The default, "both", includes boundary points on either end. - - >>> pd.date_range(start="2017-01-01", end="2017-01-04", inclusive="both") - DatetimeIndex(['2017-01-01', '2017-01-02', '2017-01-03', '2017-01-04'], - dtype='datetime64[ns]', freq='D') - - Use ``inclusive='left'`` to exclude `end` if it falls on the boundary. - - >>> pd.date_range(start="2017-01-01", end="2017-01-04", inclusive="left") - DatetimeIndex(['2017-01-01', '2017-01-02', '2017-01-03'], - dtype='datetime64[ns]', freq='D') - - Use ``inclusive='right'`` to exclude `start` if it falls on the boundary, and - similarly ``inclusive='neither'`` will exclude both `start` and `end`. - - >>> pd.date_range(start="2017-01-01", end="2017-01-04", inclusive="right") - DatetimeIndex(['2017-01-02', '2017-01-03', '2017-01-04'], - dtype='datetime64[ns]', freq='D') - - **Specify a unit** + Examples + -------- + >>> pd.date_range(start="2020-01-01", end="2020-01-05") + DatetimeIndex(['2020-01-01', '2020-01-02', '2020-01-03', '2020-01-04', '2020-01-05'], dtype='datetime64[ns]', freq='D') - >>> pd.date_range(start="2017-01-01", periods=10, freq="100YS", unit="s") - DatetimeIndex(['2017-01-01', '2117-01-01', '2217-01-01', '2317-01-01', - '2417-01-01', '2517-01-01', '2617-01-01', '2717-01-01', - '2817-01-01', '2917-01-01'], - dtype='datetime64[s]', freq='100YS-JAN') + >>> pd.date_range(start="2020-01-01", periods=3, freq="2D") + DatetimeIndex(['2020-01-01', '2020-01-03', '2020-01-05'], dtype='datetime64[ns]', freq='2D') """ if freq is None and com.any_none(periods, start, end): freq = "D" From 35f5318bd3e8066355101d338ea24c809f355773 Mon Sep 17 00:00:00 2001 From: Sachin Yadav Date: Fri, 22 Aug 2025 18:12:46 +0530 Subject: [PATCH 2/7] DOC: Fix line length in date_range docstring --- pandas/core/indexes/datetimes.py | 191 +++++++++++++++++++++++++------ 1 file changed, 156 insertions(+), 35 deletions(-) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index e9230a397706b..e6bd9218e79d0 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -836,56 +836,177 @@ def date_range( """ Return a fixed frequency DatetimeIndex. - :param start: Left bound for generating dates. Accepts string or datetime-like object. Optional. - :type start: str or datetime-like, optional + Returns the range of equally spaced time points (where the difference between any + two adjacent points is specified by the given frequency) such that they fall in the + range `[start, end]` , where the first one and the last one are, resp., the first + and last time points in that range that fall on the boundary of ``freq`` (if given + as a frequency string) or that are valid for ``freq`` (if given as a + :class:`pandas.tseries.offsets.DateOffset`). If ``freq`` is positive, the points + satisfy `start <[=] x <[=] end`, and if ``freq`` is negative, the points satisfy + `end <[=] x <[=] start`. (If exactly one of ``start``, ``end``, or ``freq`` is *not* + specified, this missing parameter can be computed given ``periods``, the number of + timesteps in the range. See the note below.) + + Parameters + ---------- + start : str or datetime-like, optional + Left bound for generating dates. + end : str or datetime-like, optional + Right bound for generating dates. + periods : int, optional + Number of periods to generate. + freq : str, Timedelta, datetime.timedelta, or DateOffset, default 'D' + Frequency strings can have multiples, e.g. '5h'. See + :ref:`here ` for a list of + frequency aliases. + tz : str or tzinfo, optional + Time zone name for returning localized DatetimeIndex, for example + 'Asia/Hong_Kong'. By default, the resulting DatetimeIndex is + timezone-naive unless timezone-aware datetime-likes are passed. + normalize : bool, default False + Normalize start/end dates to midnight before generating date range. + name : str, default None + Name of the resulting DatetimeIndex. + inclusive : {"both", "neither", "left", "right"}, default "both" + Include boundaries; Whether to set each bound as closed or open. + + .. versionadded:: 1.4.0 + unit : str, default None + Specify the desired resolution of the result. + + .. versionadded:: 2.0.0 + **kwargs + For compatibility. Has no effect on the result. + + Returns + ------- + DatetimeIndex + A DatetimeIndex object of the generated dates. + + See Also + -------- + DatetimeIndex : An immutable container for datetimes. + timedelta_range : Return a fixed frequency TimedeltaIndex. + period_range : Return a fixed frequency PeriodIndex. + interval_range : Return a fixed frequency IntervalIndex. - :param end: Right bound for generating dates. Accepts string or datetime-like object. Optional. - :type end: str or datetime-like, optional - :param periods: Number of periods to generate. Mutually exclusive with one of `start` or `end`. Optional. - :type periods: int, optional + Notes + ----- + Of the four parameters ``start``, ``end``, ``periods``, and ``freq``, + you must specify at least two and at most three; never all four together. + If ``freq`` is omitted, the resulting ``DatetimeIndex`` will have ``periods`` + linearly spaced elements between ``start`` and ``end`` (closed on both sides). + + To learn more about the frequency strings, please see + :ref:`this link`. + + Examples + -------- + **Specifying the values** - :param freq: Frequency string or offset. Determines the spacing between dates. Defaults to 'D' (day) if not specified and enough information is provided. Accepts string (e.g., '5h'), Timedelta, datetime.timedelta, or DateOffset. - :type freq: str, Timedelta, datetime.timedelta, or DateOffset, optional + The next four examples generate the same `DatetimeIndex`, but vary + the combination of `start`, `end` and `periods`. - :param tz: Time zone name or tzinfo to localize the DatetimeIndex. If not specified, the result is timezone-naive unless timezone-aware inputs are provided. - :type tz: str or tzinfo, optional + Specify `start` and `end`, with the default daily frequency. - :param normalize: Whether to normalize start/end dates to midnight before generating the date range. - :type normalize: bool, default False + >>> pd.date_range(start="1/1/2018", end="1/08/2018") + DatetimeIndex(['2018-01-01', '2018-01-02', '2018-01-03', '2018-01-04', + '2018-01-05', '2018-01-06', '2018-01-07', '2018-01-08'], + dtype='datetime64[ns]', freq='D') - :param name: Name to assign to the resulting DatetimeIndex. - :type name: str, optional + Specify timezone-aware `start` and `end`, with the default daily frequency. - :param inclusive: Whether to include boundaries. One of {"both", "neither", "left", "right"}. Default is "both". - :type inclusive: {"both", "neither", "left", "right"}, default "both" + >>> pd.date_range( + ... start=pd.to_datetime("1/1/2018").tz_localize("Europe/Berlin"), + ... end=pd.to_datetime("1/08/2018").tz_localize("Europe/Berlin"), + ... ) + DatetimeIndex(['2018-01-01 00:00:00+01:00', '2018-01-02 00:00:00+01:00', + '2018-01-03 00:00:00+01:00', '2018-01-04 00:00:00+01:00', + '2018-01-05 00:00:00+01:00', '2018-01-06 00:00:00+01:00', + '2018-01-07 00:00:00+01:00', '2018-01-08 00:00:00+01:00'], + dtype='datetime64[ns, Europe/Berlin]', freq='D') - :param unit: Specify the desired resolution of the result (e.g., 's' for seconds). - :type unit: str, optional + Specify `start` and `periods`, the number of periods (days). - :param kwargs: Additional keyword arguments for compatibility. Has no effect on the result. + >>> pd.date_range(start="1/1/2018", periods=8) + DatetimeIndex(['2018-01-01', '2018-01-02', '2018-01-03', '2018-01-04', + '2018-01-05', '2018-01-06', '2018-01-07', '2018-01-08'], + dtype='datetime64[ns]', freq='D') - :return: DatetimeIndex of the generated dates. - :rtype: DatetimeIndex + Specify `end` and `periods`, the number of periods (days). - :raises ValueError: If less than three of the four parameters (`start`, `end`, `periods`, `freq`) are specified. + >>> pd.date_range(end="1/1/2018", periods=8) + DatetimeIndex(['2017-12-25', '2017-12-26', '2017-12-27', '2017-12-28', + '2017-12-29', '2017-12-30', '2017-12-31', '2018-01-01'], + dtype='datetime64[ns]', freq='D') - .. note:: - Of the four parameters (`start`, `end`, `periods`, `freq`), exactly three must be specified. If `freq` is omitted, the resulting DatetimeIndex will have `periods` linearly spaced elements between `start` and `end` (inclusive or exclusive depending on `inclusive`). + Specify `start`, `end`, and `periods`; the frequency is generated + automatically (linearly spaced). - .. seealso:: - :class:`pandas.DatetimeIndex` : Immutable container for datetimes. - :func:`pandas.timedelta_range` : Return a fixed frequency TimedeltaIndex. - :func:`pandas.period_range` : Return a fixed frequency PeriodIndex. - :func:`pandas.interval_range` : Return a fixed frequency IntervalIndex. + >>> pd.date_range(start="2018-04-24", end="2018-04-27", periods=3) + DatetimeIndex(['2018-04-24 00:00:00', '2018-04-25 12:00:00', + '2018-04-27 00:00:00'], + dtype='datetime64[ns]', freq=None) - Examples - -------- - >>> pd.date_range(start="2020-01-01", end="2020-01-05") - DatetimeIndex(['2020-01-01', '2020-01-02', '2020-01-03', '2020-01-04', '2020-01-05'], dtype='datetime64[ns]', freq='D') + **Other Parameters** + + Changed the `freq` (frequency) to ``'ME'`` (month end frequency). + + >>> pd.date_range(start="1/1/2018", periods=5, freq="ME") + DatetimeIndex(['2018-01-31', '2018-02-28', '2018-03-31', '2018-04-30', + '2018-05-31'], + dtype='datetime64[ns]', freq='ME') + + Multiples are allowed + + >>> pd.date_range(start="1/1/2018", periods=5, freq="3ME") + DatetimeIndex(['2018-01-31', '2018-04-30', '2018-07-31', '2018-10-31', + '2019-01-31'], + dtype='datetime64[ns]', freq='3ME') + + `freq` can also be specified as an Offset object. + + >>> pd.date_range(start="1/1/2018", periods=5, freq=pd.offsets.MonthEnd(3)) + DatetimeIndex(['2018-01-31', '2018-04-30', '2018-07-31', '2018-10-31', + '2019-01-31'], + dtype='datetime64[ns]', freq='3ME') + + Specify `tz` to set the timezone. + + >>> pd.date_range(start="1/1/2018", periods=5, tz="Asia/Tokyo") + DatetimeIndex(['2018-01-01 00:00:00+09:00', '2018-01-02 00:00:00+09:00', + '2018-01-03 00:00:00+09:00', '2018-01-04 00:00:00+09:00', + '2018-01-05 00:00:00+09:00'], + dtype='datetime64[ns, Asia/Tokyo]', freq='D') + + `inclusive` controls whether to include `start` and `end` that are on the + boundary. The default, "both", includes boundary points on either end. + + >>> pd.date_range(start="2017-01-01", end="2017-01-04", inclusive="both") + DatetimeIndex(['2017-01-01', '2017-01-02', '2017-01-03', '2017-01-04'], + dtype='datetime64[ns]', freq='D') + + Use ``inclusive='left'`` to exclude `end` if it falls on the boundary. + + >>> pd.date_range(start="2017-01-01", end="2017-01-04", inclusive="left") + DatetimeIndex(['2017-01-01', '2017-01-02', '2017-01-03'], + dtype='datetime64[ns]', freq='D') + + Use ``inclusive='right'`` to exclude `start` if it falls on the boundary, and + similarly ``inclusive='neither'`` will exclude both `start` and `end`. + + >>> pd.date_range(start="2017-01-01", end="2017-01-04", inclusive="right") + DatetimeIndex(['2017-01-02', '2017-01-03', '2017-01-04'], + dtype='datetime64[ns]', freq='D') + + **Specify a unit** - >>> pd.date_range(start="2020-01-01", periods=3, freq="2D") - DatetimeIndex(['2020-01-01', '2020-01-03', '2020-01-05'], dtype='datetime64[ns]', freq='2D') + >>> pd.date_range(start="2017-01-01", periods=10, freq="100YS", unit="s") + DatetimeIndex(['2017-01-01', '2117-01-01', '2217-01-01', '2317-01-01', + '2417-01-01', '2517-01-01', '2617-01-01', '2717-01-01', + '2817-01-01', '2917-01-01'], + dtype='datetime64[s]', freq='100YS-JAN') """ if freq is None and com.any_none(periods, start, end): freq = "D" From 3ca23c8800ae781b672f6715340edfc981ba851c Mon Sep 17 00:00:00 2001 From: Sachin Yadav Date: Fri, 22 Aug 2025 18:47:42 +0530 Subject: [PATCH 3/7] DOC: Fix double line break and clarify date_range arguments --- pandas/core/indexes/datetimes.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index e6bd9218e79d0..b5f2025e6e699 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -827,18 +827,18 @@ def date_range( freq=None, tz=None, normalize: bool = False, - name: Hashable | None = None, - inclusive: IntervalClosedType = "both", + name: "Hashable | None" = None, + inclusive: "IntervalClosedType" = "both", *, unit: str | None = None, **kwargs, -) -> DatetimeIndex: +) -> "DatetimeIndex": """ Return a fixed frequency DatetimeIndex. Returns the range of equally spaced time points (where the difference between any two adjacent points is specified by the given frequency) such that they fall in the - range `[start, end]` , where the first one and the last one are, resp., the first + range `[start, end]`, where the first one and the last one are, resp., the first and last time points in that range that fall on the boundary of ``freq`` (if given as a frequency string) or that are valid for ``freq`` (if given as a :class:`pandas.tseries.offsets.DateOffset`). If ``freq`` is positive, the points @@ -857,8 +857,7 @@ def date_range( Number of periods to generate. freq : str, Timedelta, datetime.timedelta, or DateOffset, default 'D' Frequency strings can have multiples, e.g. '5h'. See - :ref:`here ` for a list of - frequency aliases. + :ref:`here ` for a list of frequency aliases. tz : str or tzinfo, optional Time zone name for returning localized DatetimeIndex, for example 'Asia/Hong_Kong'. By default, the resulting DatetimeIndex is @@ -890,7 +889,6 @@ def date_range( period_range : Return a fixed frequency PeriodIndex. interval_range : Return a fixed frequency IntervalIndex. - Notes ----- Of the four parameters ``start``, ``end``, ``periods``, and ``freq``, @@ -1008,6 +1006,7 @@ def date_range( '2817-01-01', '2917-01-01'], dtype='datetime64[s]', freq='100YS-JAN') """ + if freq is None and com.any_none(periods, start, end): freq = "D" @@ -1138,4 +1137,4 @@ def bdate_range( def _time_to_micros(time_obj: dt.time) -> int: seconds = time_obj.hour * 60 * 60 + 60 * time_obj.minute + time_obj.second - return 1_000_000 * seconds + time_obj.microsecond + return 1_000_000 * seconds + time_obj.microsecond \ No newline at end of file From 474f2b226725e7920023cd5614d5da5135015e11 Mon Sep 17 00:00:00 2001 From: Sachin Yadav Date: Fri, 22 Aug 2025 18:56:40 +0530 Subject: [PATCH 4/7] Apply auto-fixes from ruff and pyupgrade --- pandas/core/indexes/datetimes.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index b5f2025e6e699..129b8242bcde4 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -827,12 +827,12 @@ def date_range( freq=None, tz=None, normalize: bool = False, - name: "Hashable | None" = None, - inclusive: "IntervalClosedType" = "both", + name: Hashable | None = None, + inclusive: IntervalClosedType = "both", *, unit: str | None = None, **kwargs, -) -> "DatetimeIndex": +) -> DatetimeIndex: """ Return a fixed frequency DatetimeIndex. From 006e7a0cf939018e82373295f7a8eee34920d093 Mon Sep 17 00:00:00 2001 From: Sachin Yadav Date: Fri, 22 Aug 2025 19:06:58 +0530 Subject: [PATCH 5/7] style: apply ruff auto-formatting --- pandas/core/indexes/datetimes.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index 129b8242bcde4..b5f2025e6e699 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -827,12 +827,12 @@ def date_range( freq=None, tz=None, normalize: bool = False, - name: Hashable | None = None, - inclusive: IntervalClosedType = "both", + name: "Hashable | None" = None, + inclusive: "IntervalClosedType" = "both", *, unit: str | None = None, **kwargs, -) -> DatetimeIndex: +) -> "DatetimeIndex": """ Return a fixed frequency DatetimeIndex. From 71b814100a43e9e0643f7c86012903204bed2ea4 Mon Sep 17 00:00:00 2001 From: Sachin Yadav Date: Fri, 22 Aug 2025 19:13:55 +0530 Subject: [PATCH 6/7] DOC: Clarify note on date_range/timedelta_range arguments --- pandas/core/indexes/datetimes.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index b5f2025e6e699..f322a7213ae9a 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -892,9 +892,10 @@ def date_range( Notes ----- Of the four parameters ``start``, ``end``, ``periods``, and ``freq``, - you must specify at least two and at most three; never all four together. - If ``freq`` is omitted, the resulting ``DatetimeIndex`` will have ``periods`` - linearly spaced elements between ``start`` and ``end`` (closed on both sides). + at least two and at most three must be specified. You cannot specify + all four parameters together. If ``freq`` is omitted, the resulting + ``DatetimeIndex`` will have ``periods`` linearly spaced elements between + ``start`` and ``end`` (closed on both sides). To learn more about the frequency strings, please see :ref:`this link`. From a8605b39d19cc6c4133d18bda41a483f4be3dbc9 Mon Sep 17 00:00:00 2001 From: Sachin Yadav Date: Fri, 22 Aug 2025 19:18:23 +0530 Subject: [PATCH 7/7] DOC: Clarify note on date_range/timedelta_range arguments --- pandas/core/indexes/datetimes.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index f322a7213ae9a..d0faa1975773d 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -827,18 +827,18 @@ def date_range( freq=None, tz=None, normalize: bool = False, - name: "Hashable | None" = None, - inclusive: "IntervalClosedType" = "both", + name: Hashable | None = None, + inclusive: IntervalClosedType = "both", *, unit: str | None = None, **kwargs, -) -> "DatetimeIndex": +) -> DatetimeIndex: """ Return a fixed frequency DatetimeIndex. Returns the range of equally spaced time points (where the difference between any two adjacent points is specified by the given frequency) such that they fall in the - range `[start, end]`, where the first one and the last one are, resp., the first + range `[start, end]` , where the first one and the last one are, resp., the first and last time points in that range that fall on the boundary of ``freq`` (if given as a frequency string) or that are valid for ``freq`` (if given as a :class:`pandas.tseries.offsets.DateOffset`). If ``freq`` is positive, the points @@ -857,7 +857,8 @@ def date_range( Number of periods to generate. freq : str, Timedelta, datetime.timedelta, or DateOffset, default 'D' Frequency strings can have multiples, e.g. '5h'. See - :ref:`here ` for a list of frequency aliases. + :ref:`here ` for a list of + frequency aliases. tz : str or tzinfo, optional Time zone name for returning localized DatetimeIndex, for example 'Asia/Hong_Kong'. By default, the resulting DatetimeIndex is @@ -892,8 +893,7 @@ def date_range( Notes ----- Of the four parameters ``start``, ``end``, ``periods``, and ``freq``, - at least two and at most three must be specified. You cannot specify - all four parameters together. If ``freq`` is omitted, the resulting + exactly three must be specified. If ``freq`` is omitted, the resulting ``DatetimeIndex`` will have ``periods`` linearly spaced elements between ``start`` and ``end`` (closed on both sides). @@ -1007,7 +1007,6 @@ def date_range( '2817-01-01', '2917-01-01'], dtype='datetime64[s]', freq='100YS-JAN') """ - if freq is None and com.any_none(periods, start, end): freq = "D" @@ -1088,10 +1087,11 @@ def bdate_range( Notes ----- - Of the four parameters: ``start``, ``end``, ``periods``, and ``freq``, - exactly three must be specified. Specifying ``freq`` is a requirement - for ``bdate_range``. Use ``date_range`` if specifying ``freq`` is not - desired. + Of the four parameters ``start``, ``end``, ``periods``, and ``freq``, + at least two and at most three must be specified. You cannot specify + all four parameters together. If ``freq`` is omitted, the resulting + ``DatetimeIndex`` will have ``periods`` linearly spaced elements between + ``start`` and ``end`` (closed on both sides). To learn more about the frequency strings, please see :ref:`this link`.