Skip to content
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

DOC: Timestamp EX01 errors #37904

Merged
merged 33 commits into from
Apr 30, 2021
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
85f8193
SS01 errors fixed
luikn Nov 14, 2020
f459a0b
trailing-whitespace error fixed
luikn Nov 14, 2020
31f4484
merge with upstream
luikn Nov 14, 2020
b6a0da2
added coded to code_checks.sh script
luikn Nov 14, 2020
90abe5d
fixed docstrings consistency
luikn Nov 14, 2020
e99135b
mistaken file
luikn Nov 14, 2020
ac70cf4
merge upstream
luikn Nov 14, 2020
1e132b5
merge upstream
luikn Nov 15, 2020
88131f8
trailing-whitespace typo
luikn Nov 15, 2020
ee3838d
merge master
luikn Nov 15, 2020
cf5f4f1
merge upstream
luikn Nov 16, 2020
badea7b
Example section for ceil method
luikn Nov 16, 2020
d49c16d
Added example section for ceil, floor and round
luikn Nov 16, 2020
b5b26f3
example section added to methods day_name, month_name, fromordinal, u…
luikn Nov 16, 2020
3793584
trailing whitespace
luikn Nov 16, 2020
696d4d4
typo in is_quarter_start
luikn Nov 16, 2020
12e560c
typo in floor method
luikn Nov 16, 2020
8897d30
added example section for method normalize
luikn Nov 17, 2020
45bafac
typo
luikn Nov 17, 2020
b5b465a
merge upstream
luikn Nov 19, 2020
f6bb54e
recommendations from pull request review
luikn Nov 19, 2020
2f7a124
typo
luikn Nov 20, 2020
c21ebd0
merge upstream
luikn Nov 20, 2020
b4a2d2b
merge upstream
lucasrodes Nov 23, 2020
eed4712
revert changes. to be addressed in another PR
lucasrodes Nov 23, 2020
50add86
merge upstream
lucasrodes Nov 26, 2020
1563e39
Added NaT examples in nattype and timestamp docstrings where needed.
lucasrodes Nov 26, 2020
710f216
merge upstream
lucasrodes Nov 26, 2020
83edb1c
trigger GitHub actions
lucasrodes Nov 27, 2020
cfcf7b6
Merge branch 'master' into feature/docstrings-errors
Feb 17, 2021
7a09df2
Merge branch 'master' into feature/docstrings-errors
Mar 21, 2021
c622449
added missing ( in docstring examples
Mar 21, 2021
bcbf195
added missing ( in docstring example
Mar 21, 2021
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
229 changes: 228 additions & 1 deletion pandas/_libs/tslibs/nattype.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,12 @@ cdef class _NaT(datetime):
See Also
--------
DatetimeIndex.to_numpy : Similar method for DatetimeIndex.

Examples
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these need to be NaT examples (same for anything in nattype)

--------
>>> ts = pd.Timestamp('2020-03-14T15:32:52.192548651')
>>> ts.to_numpy()
numpy.datetime64('2020-03-14T15:32:52.192548651')
"""
return self.to_datetime64()

Expand Down Expand Up @@ -395,6 +401,12 @@ class NaTType(_NaT):
Returns
-------
str

Examples
--------
>>> ts = pd.Timestamp('2020-03-14T15:32:52.192548651')
>>> ts.month_name()
'March'
""",
)
day_name = _make_nan_func(
Expand All @@ -410,6 +422,12 @@ class NaTType(_NaT):
Returns
-------
str

Examples
--------
>>> ts = pd.Timestamp('2020-03-14T15:32:52.192548651')
>>> ts.day_name()
'Saturday'
""",
)
# _nat_methods
Expand Down Expand Up @@ -448,6 +466,12 @@ class NaTType(_NaT):
Format string to convert Timestamp to string.
See strftime documentation for more information on the format string:
https://docs.python.org/3/library/datetime.html#strftime-and-strptime-behavior.

Examples
--------
>>> ts = pd.Timestamp('2020-03-14T15:32:52.192548651')
>>> ts.strftime('%Y-%m-%d %X')
'2020-03-14 15:32:52'
""",
)

Expand All @@ -466,6 +490,11 @@ class NaTType(_NaT):
Timestamp.utcfromtimestamp(ts)

Construct a naive UTC datetime from a POSIX timestamp.

Examples
--------
>>> pd.Timestamp.fromtimestamp(1584199972)
Timestamp('2020-03-14 15:32:52')
""",
)
fromtimestamp = _make_error_func(
Expand All @@ -474,6 +503,13 @@ class NaTType(_NaT):
Timestamp.fromtimestamp(ts)

Transform timestamp[, tz] to tz's local time from POSIX timestamp.

Examples
--------
>>> pd.Timestamp.utcfromtimestamp(1584199972)
Timestamp('2020-03-14 15:32:52')

Note that the output may change depending on your local time.
""",
)
combine = _make_error_func(
Expand All @@ -482,6 +518,12 @@ class NaTType(_NaT):
Timestamp.combine(date, time)

Combine date, time into datetime with same date and time fields.

Examples
--------
>>> from datetime import date, time
>>> pd.Timestamp.combine(date(2020, 3, 14), time(15, 30, 15))
Timestamp('2020-03-14 15:30:15')
""",
)
utcnow = _make_error_func(
Expand All @@ -490,10 +532,26 @@ class NaTType(_NaT):
Timestamp.utcnow()

Return a new Timestamp representing UTC day and time.

Examples
--------
>>> pd.Timestamp.utcnow()
Timestamp('2020-11-16 22:50:18.092888+0000', tz='UTC')
""",
)

timestamp = _make_error_func("timestamp", "Return POSIX timestamp as float.")
timestamp = _make_error_func(
"timestamp",
"""
Return POSIX timestamp as float.

Examples
--------
>>> ts = pd.Timestamp('2020-03-14T15:32:52.192548')
>>> ts.timestamp()
1584199972.192548
"""
)

# GH9513 NaT methods (except to_datetime64) to raise, return np.nan, or
# return NaT create functions that raise, for binding to NaTType
Expand All @@ -516,6 +574,19 @@ class NaTType(_NaT):
------
TypeError
If Timestamp is tz-naive.

Examples
--------
Create a timestamp object with UTC timezone:

>>> ts = pd.Timestamp('2020-03-14T15:32:52.192548651', tz='UTC')
>>> ts
Timestamp('2020-03-14 15:32:52.192548651+0000', tz='UTC')

Change to Tokyo timezone:

>>> ts.tz_convert(tz='Asia/Tokyo')
Timestamp('2020-03-15 00:32:52.192548651+0900', tz='Asia/Tokyo')
""",
)
fromordinal = _make_error_func(
Expand All @@ -534,6 +605,11 @@ class NaTType(_NaT):
Offset to apply to the Timestamp.
tz : str, pytz.timezone, dateutil.tz.tzfile or None
Time zone for the Timestamp.

Examples
--------
>>> pd.Timestamp.fromordinal(737425)
Timestamp('2020-01-01 00:00:00')
""",
)

Expand All @@ -544,6 +620,12 @@ class NaTType(_NaT):
Convert a Timestamp object to a native Python datetime object.

If warn=True, issue a warning if nanoseconds is nonzero.

Examples
--------
>>> ts = pd.Timestamp('2020-03-14T15:32:52.192548')
>>> ts.to_pydatetime()
datetime.datetime(2020, 3, 14, 15, 32, 52, 192548)
""",
)

Expand All @@ -559,6 +641,11 @@ class NaTType(_NaT):
----------
tz : str or timezone object, default None
Timezone to localize to.

Examples
--------
>>> pd.Timestamp.now()
Timestamp('2020-11-16 22:06:16.378782')
""",
)
today = _make_nat_func(
Expand All @@ -574,6 +661,11 @@ class NaTType(_NaT):
----------
tz : str or timezone object, default None
Timezone to localize to.

Examples
--------
>>> pd.Timestamp.today()
Timestamp('2020-11-16 22:37:39.969883')
""",
)
round = _make_nat_func(
Expand Down Expand Up @@ -617,6 +709,36 @@ timedelta}, default 'raise'
Raises
------
ValueError if the freq cannot be converted

Examples
--------
Create a timestamp object:

>>> ts = pd.Timestamp('2020-03-14T15:32:52.192548651')

A timestamp can be rounded using multiple frequency units:

>>> ts.round(freq='H') # hour
Timestamp('2020-03-14 16:00:00')

>>> ts.round(freq='T') # minute
Timestamp('2020-03-14 15:33:00')

>>> ts.round(freq='S') # seconds
Timestamp('2020-03-14 15:32:52')

>>> ts.round(freq='L') # milliseconds
Timestamp('2020-03-14 15:32:52.193000')

``freq`` can also be a multiple of a single unit, like '5T' (i.e. 5 minutes):

>>> ts.round(freq='5T')
Timestamp('2020-03-14 15:35:00')

or a combination of multiple units, like '1H30T' (i.e. 1 hour and 30 minutes):

>>> ts.round(freq='1H30T')
Timestamp('2020-03-14 15:00:00')
""",
)
floor = _make_nat_func(
Expand Down Expand Up @@ -656,6 +778,36 @@ timedelta}, default 'raise'
Raises
------
ValueError if the freq cannot be converted.

Examples
--------
Create a timestamp object:

>>> ts = pd.Timestamp('2020-03-14T15:32:52.192548651')

A timestamp can be floored using multiple frequency units:

>>> ts.floor(freq='H') # hour
Timestamp('2020-03-14 15:00:00')

>>> ts.floor(freq='T') # minute
Timestamp('2020-03-14 15:32:00')

>>> ts.floor(freq='S') # seconds
Timestamp('2020-03-14 15:32:52')

>>> ts.floor(freq='N') # nanoseconds
Timestamp('2020-03-14 15:32:52.192548651')

``freq`` can also be a multiple of a single unit, like '5T' (i.e. 5 minutes):

>>> ts.floor(freq='5T')
Timestamp('2020-03-14 15:30:00')

or a combination of multiple units, like '1H30T' (i.e. 1 hour and 30 minutes):

>>> ts.floor(freq='1H30T')
Timestamp('2020-03-14 15:00:00')
""",
)
ceil = _make_nat_func(
Expand Down Expand Up @@ -695,6 +847,36 @@ timedelta}, default 'raise'
Raises
------
ValueError if the freq cannot be converted.

Examples
--------
Create a timestamp object:

>>> ts = pd.Timestamp('2020-03-14T15:32:52.192548651')

A timestamp can be ceiled using multiple frequency units:

>>> ts.ceil(freq='H') # hour
Timestamp('2020-03-14 16:00:00')

>>> ts.ceil(freq='T') # minute
Timestamp('2020-03-14 15:33:00')

>>> ts.ceil(freq='S') # seconds
Timestamp('2020-03-14 15:32:53')

>>> ts.ceil(freq='U') # microseconds
Timestamp('2020-03-14 15:32:52.192549')

``freq`` can also be a multiple of a single unit, like '5T' (i.e. 5 minutes):

>>> ts.ceil(freq='5T')
Timestamp('2020-03-14 15:35:00')

or a combination of multiple units, like '1H30T' (i.e. 1 hour and 30 minutes):

>>> ts.ceil(freq='1H30T')
Timestamp('2020-03-14 16:30:00')
""",
)

Expand All @@ -717,6 +899,19 @@ timedelta}, default 'raise'
------
TypeError
If Timestamp is tz-naive.

Examples
--------
Create a timestamp object with UTC timezone:

>>> ts = pd.Timestamp('2020-03-14T15:32:52.192548651', tz='UTC')
>>> ts
Timestamp('2020-03-14 15:32:52.192548651+0000', tz='UTC')

Change to Tokyo timezone:

>>> ts.tz_convert(tz='Asia/Tokyo')
Timestamp('2020-03-15 00:32:52.192548651+0900', tz='Asia/Tokyo')
""",
)
tz_localize = _make_nat_func(
Expand Down Expand Up @@ -772,6 +967,19 @@ default 'raise'
------
TypeError
If the Timestamp is tz-aware and tz is not None.

Examples
--------
Create a naive timestamp object:

>>> ts = pd.Timestamp('2020-03-14T15:32:52.192548651')
>>> ts
Timestamp('2020-03-14 15:32:52.192548651')

Add 'Europe/Stockholm' as timezone:

>>> ts.tz_localize(tz='Europe/Stockholm')
Timestamp('2020-03-14 15:32:52.192548651+0100', tz='Europe/Stockholm')
""",
)
replace = _make_nat_func(
Expand All @@ -795,6 +1003,25 @@ default 'raise'
Returns
-------
Timestamp with fields replaced

Examples
--------
Create a timestamp object:

>>> ts = pd.Timestamp('2020-03-14T15:32:52.192548651', tz='UTC')
>>> ts
Timestamp('2020-03-14 15:32:52.192548651+0000', tz='UTC')

Replace year and the hour:

>>> ts.replace(year=1999, hour=10)
Timestamp('1999-03-14 10:32:52.192548651+0000', tz='UTC')

Replace timezone (not a conversion):

>>> import pytz
>>> ts.replace(tzinfo=pytz.timezone('US/Pacific'))
Timestamp('2020-03-14 15:32:52.192548651-0700', tz='US/Pacific')
""",
)

Expand Down
Loading