Skip to content

Commit a162c40

Browse files
DeaMariaLeonphofl
andauthored
DOC Fix EX01 issues in docstrings (#51440)
* DOC Fix EX01 issues in docstrings * DOC Fix EX01- correct var name+added to example --------- Co-authored-by: Patrick Hoefler <[email protected]>
1 parent 6e29dbf commit a162c40

File tree

4 files changed

+67
-3
lines changed

4 files changed

+67
-3
lines changed

ci/code_checks.sh

-3
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
9191
pandas.Series.size \
9292
pandas.Series.T \
9393
pandas.Series.hasnans \
94-
pandas.Series.to_timestamp \
9594
pandas.Series.to_list \
9695
pandas.Series.__iter__ \
9796
pandas.Series.keys \
@@ -218,7 +217,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
218217
pandas.Period.year \
219218
pandas.Period.asfreq \
220219
pandas.Period.now \
221-
pandas.Period.to_timestamp \
222220
pandas.arrays.PeriodArray \
223221
pandas.Interval.closed \
224222
pandas.Interval.left \
@@ -562,7 +560,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
562560
pandas.DataFrame.swapaxes \
563561
pandas.DataFrame.first_valid_index \
564562
pandas.DataFrame.last_valid_index \
565-
pandas.DataFrame.to_timestamp \
566563
pandas.DataFrame.attrs \
567564
pandas.DataFrame.plot \
568565
pandas.DataFrame.sparse.density \

pandas/_libs/tslibs/period.pyx

+7
Original file line numberDiff line numberDiff line change
@@ -1841,6 +1841,13 @@ cdef class _Period(PeriodMixin):
18411841
Returns
18421842
-------
18431843
Timestamp
1844+
1845+
Examples
1846+
--------
1847+
>>> period = pd.Period('2023-1-1', freq='D')
1848+
>>> timestamp = period.to_timestamp()
1849+
>>> timestamp
1850+
Timestamp('2023-01-01 00:00:00')
18441851
"""
18451852
how = validate_end_alias(how)
18461853

pandas/core/frame.py

+31
Original file line numberDiff line numberDiff line change
@@ -11010,6 +11010,37 @@ def to_timestamp(
1101011010
-------
1101111011
DataFrame
1101211012
The DataFrame has a DatetimeIndex.
11013+
11014+
Examples
11015+
--------
11016+
>>> idx = pd.PeriodIndex(['2023', '2024'], freq='Y')
11017+
>>> d = {'col1': [1, 2], 'col2': [3, 4]}
11018+
>>> df1 = pd.DataFrame(data=d, index=idx)
11019+
>>> df1
11020+
col1 col2
11021+
2023 1 3
11022+
2024 2 4
11023+
11024+
The resulting timestamps will be at the beginning of the year in this case
11025+
11026+
>>> df1 = df1.to_timestamp()
11027+
>>> df1
11028+
col1 col2
11029+
2023-01-01 1 3
11030+
2024-01-01 2 4
11031+
>>> df1.index
11032+
DatetimeIndex(['2023-01-01', '2024-01-01'], dtype='datetime64[ns]', freq=None)
11033+
11034+
Using `freq` which is the offset that the Timestamps will have
11035+
11036+
>>> df2 = pd.DataFrame(data=d, index=idx)
11037+
>>> df2 = df2.to_timestamp(freq='M')
11038+
>>> df2
11039+
col1 col2
11040+
2023-01-31 1 3
11041+
2024-01-31 2 4
11042+
>>> df2.index
11043+
DatetimeIndex(['2023-01-31', '2024-01-31'], dtype='datetime64[ns]', freq=None)
1101311044
"""
1101411045
new_obj = self.copy(deep=copy)
1101511046

pandas/core/series.py

+29
Original file line numberDiff line numberDiff line change
@@ -5710,6 +5710,35 @@ def to_timestamp(
57105710
Returns
57115711
-------
57125712
Series with DatetimeIndex
5713+
5714+
Examples
5715+
--------
5716+
>>> idx = pd.PeriodIndex(['2023', '2024', '2025'], freq='Y')
5717+
>>> s1 = pd.Series([1, 2, 3], index=idx)
5718+
>>> s1
5719+
2023 1
5720+
2024 2
5721+
2025 3
5722+
Freq: A-DEC, dtype: int64
5723+
5724+
The resulting frequency of the Timestamps is `YearBegin`
5725+
5726+
>>> s1 = s1.to_timestamp()
5727+
>>> s1
5728+
2023-01-01 1
5729+
2024-01-01 2
5730+
2025-01-01 3
5731+
Freq: AS-JAN, dtype: int64
5732+
5733+
Using `freq` which is the offset that the Timestamps will have
5734+
5735+
>>> s2 = pd.Series([1, 2, 3], index=idx)
5736+
>>> s2 = s2.to_timestamp(freq='M')
5737+
>>> s2
5738+
2023-01-31 1
5739+
2024-01-31 2
5740+
2025-01-31 3
5741+
Freq: A-JAN, dtype: int64
57135742
"""
57145743
if not isinstance(self.index, PeriodIndex):
57155744
raise TypeError(f"unsupported Type {type(self.index).__name__}")

0 commit comments

Comments
 (0)