Skip to content

DOC: Fixing EX01 - Added examples #53262

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
pandas.Series.backfill \
pandas.Series.ffill \
pandas.Series.pad \
pandas.Series.dt.date \
pandas.Series.dt.time \
pandas.Series.dt.timetz \
pandas.Series.dt.dayofyear \
pandas.Series.dt.day_of_year \
pandas.Series.dt.quarter \
pandas.Series.dt.daysinmonth \
pandas.Series.dt.days_in_month \
pandas.Series.dt.tz \
pandas.Series.dt.end_time \
pandas.Series.dt.days \
pandas.Series.dt.seconds \
pandas.Series.dt.microseconds \
Expand Down
5 changes: 5 additions & 0 deletions pandas/_libs/tslibs/period.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1661,6 +1661,11 @@ cdef class PeriodMixin:
Period.dayofyear : Return the day of year.
Period.daysinmonth : Return the days in that month.
Period.dayofweek : Return the day of the week.

Examples
--------
>>> pd.Period('2020-01', 'D').end_time
Timestamp('2020-01-01 23:59:59.999999999')
"""
return self.to_timestamp(how="end")

Expand Down
89 changes: 89 additions & 0 deletions pandas/core/arrays/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,17 @@ def tz(self) -> tzinfo | None:
-------
datetime.tzinfo, pytz.tzinfo.BaseTZInfo, dateutil.tz.tz.tzfile, or None
Returns None when the array is tz-naive.

Examples
--------
>>> s = pd.Series(["1/1/2020 10:00:00+00:00", "2/1/2020 11:00:00+00:00"])
>>> s = pd.to_datetime(s)
>>> s
0 2020-01-01 10:00:00+00:00
1 2020-02-01 11:00:00+00:00
dtype: datetime64[ns, UTC]
>>> s.dt.tz
datetime.timezone.utc
"""
# GH 18595
return getattr(self.dtype, "tz", None)
Expand Down Expand Up @@ -1312,6 +1323,19 @@ def time(self) -> npt.NDArray[np.object_]:
Returns numpy array of :class:`datetime.time` objects.

The time part of the Timestamps.

Examples
--------
>>> s = pd.Series(["1/1/2020 10:00:00+00:00", "2/1/2020 11:00:00+00:00"])
>>> s = pd.to_datetime(s)
>>> s
0 2020-01-01 10:00:00+00:00
1 2020-02-01 11:00:00+00:00
dtype: datetime64[ns, UTC]
>>> s.dt.time
0 10:00:00
1 11:00:00
dtype: object
"""
# If the Timestamps have a timezone that is not UTC,
# convert them into their i8 representation while
Expand All @@ -1326,6 +1350,19 @@ def timetz(self) -> npt.NDArray[np.object_]:
Returns numpy array of :class:`datetime.time` objects with timezones.

The time part of the Timestamps.

Examples
--------
>>> s = pd.Series(["1/1/2020 10:00:00+00:00", "2/1/2020 11:00:00+00:00"])
>>> s = pd.to_datetime(s)
>>> s
0 2020-01-01 10:00:00+00:00
1 2020-02-01 11:00:00+00:00
dtype: datetime64[ns, UTC]
>>> s.dt.timetz
0 10:00:00+00:00
1 11:00:00+00:00
dtype: object
"""
return ints_to_pydatetime(self.asi8, self.tz, box="time", reso=self._creso)

Expand All @@ -1336,6 +1373,19 @@ def date(self) -> npt.NDArray[np.object_]:

Namely, the date part of Timestamps without time and
timezone information.

Examples
--------
>>> s = pd.Series(["1/1/2020 10:00:00+00:00", "2/1/2020 11:00:00+00:00"])
>>> s = pd.to_datetime(s)
>>> s
0 2020-01-01 10:00:00+00:00
1 2020-02-01 11:00:00+00:00
dtype: datetime64[ns, UTC]
>>> s.dt.date
0 2020-01-01
1 2020-02-01
dtype: object
"""
# If the Timestamps have a timezone that is not UTC,
# convert them into their i8 representation while
Expand Down Expand Up @@ -1614,6 +1664,19 @@ def isocalendar(self) -> DataFrame:
"doy",
"""
The ordinal day of the year.

Examples
--------
>>> s = pd.Series(["1/1/2020 10:00:00+00:00", "2/1/2020 11:00:00+00:00"])
>>> s = pd.to_datetime(s)
>>> s
0 2020-01-01 10:00:00+00:00
1 2020-02-01 11:00:00+00:00
dtype: datetime64[ns, UTC]
>>> s.dt.dayofyear
0 1
1 32
dtype: int32
""",
)
dayofyear = day_of_year
Expand All @@ -1622,13 +1685,39 @@ def isocalendar(self) -> DataFrame:
"q",
"""
The quarter of the date.

Examples
--------
>>> s = pd.Series(["1/1/2020 10:00:00+00:00", "4/1/2020 11:00:00+00:00"])
>>> s = pd.to_datetime(s)
>>> s
0 2020-01-01 10:00:00+00:00
1 2020-04-01 11:00:00+00:00
dtype: datetime64[ns, UTC]
>>> s.dt.quarter
0 1
1 2
dtype: int32
""",
)
days_in_month = _field_accessor(
"days_in_month",
"dim",
"""
The number of days in the month.

Examples
--------
>>> s = pd.Series(["1/1/2020 10:00:00+00:00", "2/1/2020 11:00:00+00:00"])
>>> s = pd.to_datetime(s)
>>> s
0 2020-01-01 10:00:00+00:00
1 2020-02-01 11:00:00+00:00
dtype: datetime64[ns, UTC]
>>> s.dt.daysinmonth
0 31
1 29
dtype: int32
""",
)
daysinmonth = days_in_month
Expand Down
15 changes: 15 additions & 0 deletions pandas/core/arrays/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,21 @@ def __arrow_array__(self, type=None):
"days_in_month",
"""
The number of days in the month.

Examples
--------
>>> period = pd.period_range('2020-1-1 00:00', '2020-3-1 00:00', freq='M')
>>> s = pd.Series(period)
>>> s
0 2020-01
1 2020-02
2 2020-03
dtype: period[M]
>>> s.dt.days_in_month
0 31
1 29
2 31
dtype: int64
""",
)
daysinmonth = days_in_month
Expand Down