Skip to content

Commit 649b051

Browse files
author
cloudboat
committed
Try to fix Summary should fit in a single line
1 parent bd4127b commit 649b051

File tree

2 files changed

+31
-26
lines changed

2 files changed

+31
-26
lines changed

pandas/core/arrays/datetimelike.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,7 @@ def freqstr(self) -> str | None:
908908
def inferred_freq(self) -> str | None:
909909
"""
910910
Tries to return a string representing a frequency generated by infer_freq.
911+
911912
Returns None if it can't autodetect the frequency.
912913
913914
See Also

pandas/core/indexes/datetimelike.py

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -138,34 +138,30 @@ def mean(self, *, skipna: bool = True, axis: int | None = 0):
138138
@property
139139
def freq(self) -> BaseOffset | None:
140140
"""
141-
Return the frequency object as a string if it's set, otherwise None.
141+
Return the frequency object if it is set, otherwise None.
142+
143+
To learn more about the frequency strings, please see
144+
:ref:`this link<timeseries.offset_aliases>`.
142145
143146
See Also
144147
--------
145-
DatetimeIndex.inferred_freq : Returns a string representing a frequency
146-
generated by infer_freq.
148+
DatetimeIndex.freq : Return the frequency object if it is set, otherwise None.
149+
PeriodIndex.freq : Return the frequency object if it is set, otherwise None.
147150
148151
Examples
149152
--------
150-
For DatetimeIndex:
151-
152-
>>> idx = pd.DatetimeIndex(["1/1/2020 10:00:00+00:00"], freq="D")
153-
>>> idx.freqstr
154-
'D'
155-
156-
The frequency can be inferred if there are more than 2 points:
157-
158-
>>> idx = pd.DatetimeIndex(
159-
... ["2018-01-01", "2018-01-03", "2018-01-05"], freq="infer"
153+
>>> datetimeindex = pd.date_range(
154+
... "2022-02-22 02:22:22", periods=10, tz="America/Chicago", freq="h"
160155
... )
161-
>>> idx.freqstr
162-
'2D'
163-
164-
For PeriodIndex:
165-
166-
>>> idx = pd.PeriodIndex(["2023-1", "2023-2", "2023-3"], freq="M")
167-
>>> idx.freqstr
168-
'M'
156+
>>> datetimeindex
157+
DatetimeIndex(['2022-02-22 02:22:22-06:00', '2022-02-22 03:22:22-06:00',
158+
'2022-02-22 04:22:22-06:00', '2022-02-22 05:22:22-06:00',
159+
'2022-02-22 06:22:22-06:00', '2022-02-22 07:22:22-06:00',
160+
'2022-02-22 08:22:22-06:00', '2022-02-22 09:22:22-06:00',
161+
'2022-02-22 10:22:22-06:00', '2022-02-22 11:22:22-06:00'],
162+
dtype='datetime64[ns, America/Chicago]', freq='h')
163+
>>> datetimeindex.freq
164+
<Hour>
169165
"""
170166
return self._data.freq
171167

@@ -669,21 +665,29 @@ def shift(self, periods: int = 1, freq=None) -> Self:
669665
@cache_readonly
670666
def inferred_freq(self) -> str | None:
671667
"""
672-
Tries to return a string representing a frequency generated by infer_freq.
673-
Returns None if it can't autodetect the frequency.
668+
Return the inferred frequency of the index.
669+
670+
Returns
671+
-------
672+
str or None
673+
A string representing a frequency generated by ``infer_freq``.
674+
Returns ``None`` if the frequency cannot be inferred.
674675
675676
See Also
676677
--------
677678
DatetimeIndex.freqstr : Return the frequency object as a string if it's set,
678-
otherwise None.
679+
otherwise ``None``.
679680
680681
Examples
681682
--------
682-
For DatetimeIndex:
683+
For ``DatetimeIndex``:
684+
683685
>>> idx = pd.DatetimeIndex(["2018-01-01", "2018-01-03", "2018-01-05"])
684686
>>> idx.inferred_freq
685687
'2D'
686-
For TimedeltaIndex:
688+
689+
For ``TimedeltaIndex``:
690+
687691
>>> tdelta_idx = pd.to_timedelta(["0 days", "10 days", "20 days"])
688692
>>> tdelta_idx
689693
TimedeltaIndex(['0 days', '10 days', '20 days'],

0 commit comments

Comments
 (0)