Skip to content

Commit 194e457

Browse files
DeaMariaLeontopper-123
authored andcommitted
DOC: Fixing EX01 - Added examples (pandas-dev#53389)
* Examples Series.dt.sec, µs, ns * updated code_checks.sh
1 parent ca8047a commit 194e457

File tree

2 files changed

+57
-6
lines changed

2 files changed

+57
-6
lines changed

ci/code_checks.sh

-3
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
8383
pandas.Series.backfill \
8484
pandas.Series.ffill \
8585
pandas.Series.pad \
86-
pandas.Series.dt.seconds \
87-
pandas.Series.dt.microseconds \
88-
pandas.Series.dt.nanoseconds \
8986
pandas.Series.str.center \
9087
pandas.Series.str.decode \
9188
pandas.Series.str.encode \

pandas/core/arrays/timedeltas.py

+57-3
Original file line numberDiff line numberDiff line change
@@ -817,20 +817,74 @@ def to_pytimedelta(self) -> npt.NDArray[np.object_]:
817817
dtype: int64"""
818818
)
819819
days = _field_accessor("days", "days", days_docstring)
820+
821+
seconds_docstring = textwrap.dedent(
822+
"""Number of seconds (>= 0 and less than 1 day) for each element.
823+
824+
Examples
825+
--------
826+
>>> ser = pd.Series(pd.to_timedelta([1, 2, 3], unit='S'))
827+
>>> ser
828+
0 0 days 00:00:01
829+
1 0 days 00:00:02
830+
2 0 days 00:00:03
831+
dtype: timedelta64[ns]
832+
>>> ser.dt.seconds
833+
0 1
834+
1 2
835+
2 3
836+
dtype: int32"""
837+
)
820838
seconds = _field_accessor(
821839
"seconds",
822840
"seconds",
823-
"Number of seconds (>= 0 and less than 1 day) for each element.",
841+
seconds_docstring,
842+
)
843+
844+
microseconds_docstring = textwrap.dedent(
845+
"""Number of microseconds (>= 0 and less than 1 second) for each element.
846+
847+
Examples
848+
--------
849+
>>> ser = pd.Series(pd.to_timedelta([1, 2, 3], unit='U'))
850+
>>> ser
851+
0 0 days 00:00:00.000001
852+
1 0 days 00:00:00.000002
853+
2 0 days 00:00:00.000003
854+
dtype: timedelta64[ns]
855+
>>> ser.dt.microseconds
856+
0 1
857+
1 2
858+
2 3
859+
dtype: int32"""
824860
)
825861
microseconds = _field_accessor(
826862
"microseconds",
827863
"microseconds",
828-
"Number of microseconds (>= 0 and less than 1 second) for each element.",
864+
microseconds_docstring,
865+
)
866+
867+
nanoseconds_docstring = textwrap.dedent(
868+
"""Number of nanoseconds (>= 0 and less than 1 microsecond) for each element.
869+
870+
Examples
871+
--------
872+
>>> ser = pd.Series(pd.to_timedelta([1, 2, 3], unit='N'))
873+
>>> ser
874+
0 0 days 00:00:00.000000001
875+
1 0 days 00:00:00.000000002
876+
2 0 days 00:00:00.000000003
877+
dtype: timedelta64[ns]
878+
>>> ser.dt.nanoseconds
879+
0 1
880+
1 2
881+
2 3
882+
dtype: int32"""
829883
)
830884
nanoseconds = _field_accessor(
831885
"nanoseconds",
832886
"nanoseconds",
833-
"Number of nanoseconds (>= 0 and less than 1 microsecond) for each element.",
887+
nanoseconds_docstring,
834888
)
835889

836890
@property

0 commit comments

Comments
 (0)