Skip to content

DOC: Fixing EX01 - Added examples #53619

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 2 commits into from
Jun 12, 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
2 changes: 0 additions & 2 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
pandas.errors.UnsupportedFunctionCall \
pandas.test \
pandas.NaT \
pandas.Timestamp.as_unit \
pandas.Timestamp.ctime \
pandas.Timestamp.date \
pandas.Timestamp.dst \
pandas.Timestamp.isocalendar \
Expand Down
29 changes: 28 additions & 1 deletion pandas/_libs/tslibs/nattype.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,6 @@ class NaTType(_NaT):
timetuple = _make_error_func("timetuple", datetime)
isocalendar = _make_error_func("isocalendar", datetime)
dst = _make_error_func("dst", datetime)
ctime = _make_error_func("ctime", datetime)
time = _make_error_func("time", datetime)
toordinal = _make_error_func("toordinal", datetime)
tzname = _make_error_func("tzname", datetime)
Expand All @@ -514,6 +513,21 @@ class NaTType(_NaT):
# The remaining methods have docstrings copy/pasted from the analogous
# Timestamp methods.

ctime = _make_error_func(
"ctime",
"""
Return ctime() style string.

Examples
--------
>>> ts = pd.Timestamp('2023-01-01 10:00:00.00')
>>> ts
Timestamp('2023-01-01 10:00:00')
>>> ts.ctime()
'Sun Jan 1 10:00:00 2023'
""",
)

strftime = _make_error_func(
"strftime",
"""
Expand Down Expand Up @@ -1210,6 +1224,19 @@ default 'raise'
Returns
-------
Timestamp

Examples
--------
>>> ts = pd.Timestamp('2023-01-01 00:00:00.01')
>>> ts
Timestamp('2023-01-01 00:00:00.010000')
>>> ts.unit
'ms'
>>> ts = ts.as_unit('s')
>>> ts
Timestamp('2023-01-01 00:00:00')
>>> ts.unit
's'
"""
return c_NaT

Expand Down
38 changes: 38 additions & 0 deletions pandas/_libs/tslibs/timestamps.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1122,6 +1122,19 @@ cdef class _Timestamp(ABCTimestamp):
Returns
-------
Timestamp

Examples
--------
>>> ts = pd.Timestamp('2023-01-01 00:00:00.01')
>>> ts
Timestamp('2023-01-01 00:00:00.010000')
>>> ts.unit
'ms'
>>> ts = ts.as_unit('s')
>>> ts
Timestamp('2023-01-01 00:00:00')
>>> ts.unit
's'
"""
dtype = np.dtype(f"M8[{unit}]")
reso = get_unit_from_dtype(dtype)
Expand Down Expand Up @@ -1493,6 +1506,31 @@ class Timestamp(_Timestamp):
) from err
return _dt.strftime(format)

def ctime(self):
"""
Return ctime() style string.

Examples
--------
>>> ts = pd.Timestamp('2023-01-01 10:00:00.00')
>>> ts
Timestamp('2023-01-01 10:00:00')
>>> ts.ctime()
'Sun Jan 1 10:00:00 2023'
"""
try:
_dt = datetime(self.year, self.month, self.day,
self.hour, self.minute, self.second,
self.microsecond, self.tzinfo, fold=self.fold)
except ValueError as err:
raise NotImplementedError(
"ctime not yet supported on Timestamps which "
"are outside the range of Python's standard library. "
"For now, please call the components you need (such as `.year` "
"and `.month`) and construct your string from there."
) from err
return _dt.ctime()

# Issue 25016.
@classmethod
def strptime(cls, date_string, format):
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/scalar/test_nat.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ def test_nat_arithmetic_ndarray(dtype, op, out_dtype):

def test_nat_pinned_docstrings():
# see gh-17327
assert NaT.ctime.__doc__ == datetime.ctime.__doc__
assert NaT.ctime.__doc__ == Timestamp.ctime.__doc__


def test_to_numpy_alias():
Expand Down