Skip to content

Commit 373918f

Browse files
DeaMariaLeonMarcoGorelli
authored andcommitted
DOC: Fixing EX01 - Added examples (pandas-dev#53262)
* Added examples * Changed end_time example * Update pandas/core/arrays/datetimes.py --------- Co-authored-by: Marco Edward Gorelli <[email protected]>
1 parent 7e10056 commit 373918f

File tree

4 files changed

+109
-10
lines changed

4 files changed

+109
-10
lines changed

ci/code_checks.sh

-10
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
8383
pandas.Series.backfill \
8484
pandas.Series.ffill \
8585
pandas.Series.pad \
86-
pandas.Series.dt.date \
87-
pandas.Series.dt.time \
88-
pandas.Series.dt.timetz \
89-
pandas.Series.dt.dayofyear \
90-
pandas.Series.dt.day_of_year \
91-
pandas.Series.dt.quarter \
92-
pandas.Series.dt.daysinmonth \
93-
pandas.Series.dt.days_in_month \
94-
pandas.Series.dt.tz \
95-
pandas.Series.dt.end_time \
9686
pandas.Series.dt.days \
9787
pandas.Series.dt.seconds \
9888
pandas.Series.dt.microseconds \

pandas/_libs/tslibs/period.pyx

+5
Original file line numberDiff line numberDiff line change
@@ -1661,6 +1661,11 @@ cdef class PeriodMixin:
16611661
Period.dayofyear : Return the day of year.
16621662
Period.daysinmonth : Return the days in that month.
16631663
Period.dayofweek : Return the day of the week.
1664+
1665+
Examples
1666+
--------
1667+
>>> pd.Period('2020-01', 'D').end_time
1668+
Timestamp('2020-01-01 23:59:59.999999999')
16641669
"""
16651670
return self.to_timestamp(how="end")
16661671

pandas/core/arrays/datetimes.py

+89
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,17 @@ def tz(self) -> tzinfo | None:
564564
-------
565565
datetime.tzinfo, pytz.tzinfo.BaseTZInfo, dateutil.tz.tz.tzfile, or None
566566
Returns None when the array is tz-naive.
567+
568+
Examples
569+
--------
570+
>>> s = pd.Series(["1/1/2020 10:00:00+00:00", "2/1/2020 11:00:00+00:00"])
571+
>>> s = pd.to_datetime(s)
572+
>>> s
573+
0 2020-01-01 10:00:00+00:00
574+
1 2020-02-01 11:00:00+00:00
575+
dtype: datetime64[ns, UTC]
576+
>>> s.dt.tz
577+
datetime.timezone.utc
567578
"""
568579
# GH 18595
569580
return getattr(self.dtype, "tz", None)
@@ -1312,6 +1323,19 @@ def time(self) -> npt.NDArray[np.object_]:
13121323
Returns numpy array of :class:`datetime.time` objects.
13131324
13141325
The time part of the Timestamps.
1326+
1327+
Examples
1328+
--------
1329+
>>> s = pd.Series(["1/1/2020 10:00:00+00:00", "2/1/2020 11:00:00+00:00"])
1330+
>>> s = pd.to_datetime(s)
1331+
>>> s
1332+
0 2020-01-01 10:00:00+00:00
1333+
1 2020-02-01 11:00:00+00:00
1334+
dtype: datetime64[ns, UTC]
1335+
>>> s.dt.time
1336+
0 10:00:00
1337+
1 11:00:00
1338+
dtype: object
13151339
"""
13161340
# If the Timestamps have a timezone that is not UTC,
13171341
# convert them into their i8 representation while
@@ -1326,6 +1350,19 @@ def timetz(self) -> npt.NDArray[np.object_]:
13261350
Returns numpy array of :class:`datetime.time` objects with timezones.
13271351
13281352
The time part of the Timestamps.
1353+
1354+
Examples
1355+
--------
1356+
>>> s = pd.Series(["1/1/2020 10:00:00+00:00", "2/1/2020 11:00:00+00:00"])
1357+
>>> s = pd.to_datetime(s)
1358+
>>> s
1359+
0 2020-01-01 10:00:00+00:00
1360+
1 2020-02-01 11:00:00+00:00
1361+
dtype: datetime64[ns, UTC]
1362+
>>> s.dt.timetz
1363+
0 10:00:00+00:00
1364+
1 11:00:00+00:00
1365+
dtype: object
13291366
"""
13301367
return ints_to_pydatetime(self.asi8, self.tz, box="time", reso=self._creso)
13311368

@@ -1336,6 +1373,19 @@ def date(self) -> npt.NDArray[np.object_]:
13361373
13371374
Namely, the date part of Timestamps without time and
13381375
timezone information.
1376+
1377+
Examples
1378+
--------
1379+
>>> s = pd.Series(["1/1/2020 10:00:00+00:00", "2/1/2020 11:00:00+00:00"])
1380+
>>> s = pd.to_datetime(s)
1381+
>>> s
1382+
0 2020-01-01 10:00:00+00:00
1383+
1 2020-02-01 11:00:00+00:00
1384+
dtype: datetime64[ns, UTC]
1385+
>>> s.dt.date
1386+
0 2020-01-01
1387+
1 2020-02-01
1388+
dtype: object
13391389
"""
13401390
# If the Timestamps have a timezone that is not UTC,
13411391
# convert them into their i8 representation while
@@ -1614,6 +1664,19 @@ def isocalendar(self) -> DataFrame:
16141664
"doy",
16151665
"""
16161666
The ordinal day of the year.
1667+
1668+
Examples
1669+
--------
1670+
>>> s = pd.Series(["1/1/2020 10:00:00+00:00", "2/1/2020 11:00:00+00:00"])
1671+
>>> s = pd.to_datetime(s)
1672+
>>> s
1673+
0 2020-01-01 10:00:00+00:00
1674+
1 2020-02-01 11:00:00+00:00
1675+
dtype: datetime64[ns, UTC]
1676+
>>> s.dt.dayofyear
1677+
0 1
1678+
1 32
1679+
dtype: int32
16171680
""",
16181681
)
16191682
dayofyear = day_of_year
@@ -1622,13 +1685,39 @@ def isocalendar(self) -> DataFrame:
16221685
"q",
16231686
"""
16241687
The quarter of the date.
1688+
1689+
Examples
1690+
--------
1691+
>>> s = pd.Series(["1/1/2020 10:00:00+00:00", "4/1/2020 11:00:00+00:00"])
1692+
>>> s = pd.to_datetime(s)
1693+
>>> s
1694+
0 2020-01-01 10:00:00+00:00
1695+
1 2020-04-01 11:00:00+00:00
1696+
dtype: datetime64[ns, UTC]
1697+
>>> s.dt.quarter
1698+
0 1
1699+
1 2
1700+
dtype: int32
16251701
""",
16261702
)
16271703
days_in_month = _field_accessor(
16281704
"days_in_month",
16291705
"dim",
16301706
"""
16311707
The number of days in the month.
1708+
1709+
Examples
1710+
--------
1711+
>>> s = pd.Series(["1/1/2020 10:00:00+00:00", "2/1/2020 11:00:00+00:00"])
1712+
>>> s = pd.to_datetime(s)
1713+
>>> s
1714+
0 2020-01-01 10:00:00+00:00
1715+
1 2020-02-01 11:00:00+00:00
1716+
dtype: datetime64[ns, UTC]
1717+
>>> s.dt.daysinmonth
1718+
0 31
1719+
1 29
1720+
dtype: int32
16321721
""",
16331722
)
16341723
daysinmonth = days_in_month

pandas/core/arrays/period.py

+15
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,21 @@ def __arrow_array__(self, type=None):
483483
"days_in_month",
484484
"""
485485
The number of days in the month.
486+
487+
Examples
488+
--------
489+
>>> period = pd.period_range('2020-1-1 00:00', '2020-3-1 00:00', freq='M')
490+
>>> s = pd.Series(period)
491+
>>> s
492+
0 2020-01
493+
1 2020-02
494+
2 2020-03
495+
dtype: period[M]
496+
>>> s.dt.days_in_month
497+
0 31
498+
1 29
499+
2 31
500+
dtype: int64
486501
""",
487502
)
488503
daysinmonth = days_in_month

0 commit comments

Comments
 (0)