In tslib.pyx there is an inheritance chain (rearranged here for python-friendliness)
cdef class _Timestamp(datetime):
[...]
cdef class _NaT(_Timestamp)
[...]
class NaTType(_NaT):
[...]
[...stuff I'm about to ask about...]
NaT = NaTType()
A bunch of attributes are pinned to NaTType
that look like they could be pinned to _NaT
just as easily. What's the reason for this? My understanding is that pinning things to _NaT
should be more performant in general.
# inject the Timestamp field properties
# these by definition return np.nan
fields = ['year', 'quarter', 'month', 'day', 'hour',
'minute', 'second', 'millisecond', 'microsecond', 'nanosecond',
'week', 'dayofyear', 'weekofyear', 'days_in_month', 'daysinmonth',
'dayofweek', 'weekday_name', 'days', 'seconds', 'microseconds',
'nanoseconds', 'qyear', 'quarter']
for field in fields:
prop = property(fget=lambda self: np.nan)
setattr(NaTType, field, prop)
Comment From: jbrockmendel
Parking an actual bug here, will get around to it before long.
A few lines further down:
# GH9513 NaT methods (except to_datetime64) to raise, return np.nan, or
# return NaT create functions that raise, for binding to NaTType
for _maybe_method_name in dir(NaTType):
_maybe_method = getattr(NaTType, _maybe_method_name)
if (callable(_maybe_method)
and not _maybe_method_name.startswith("_")
and _maybe_method_name not in _implemented_methods):
def _make_error_func(func_name):
def f(*args, **kwargs):
raise ValueError("NaTType does not support " + func_name)
f.__name__ = func_name
f.__doc__ = _get_docstring(func_name)
return f
setattr(NaTType, _maybe_method_name,
_make_error_func(_maybe_method_name))
_get_docstring(_method_name)
should be _get_docstring(_maybe_method_name)
. Demonstration:
>>> print(pd.NaT.total_seconds.__doc__)
Total duration of timedelta in seconds (to ns precision)
>>> print(pd.NaT.ctime.__doc__)
Total duration of timedelta in seconds (to ns precision)
Comment From: jreback
_NaT
is a private cython class that is not exposed.
I guess you could define this for .ctime
. All of the methods that are not explicitly defined are errors.
Comment From: jreback
if you want to make a specific issue of things to do on NaT that is fine. but pls don't mix issues.
Comment From: jbrockmendel
I guess you could define this for
.ctime
. All of the methods that are not explicitly defined are errors.
The code that defines this error-raising methods is also pinning docstrings to these methods. The methods are right, but it's mixing up the docstrings. Not a big deal, but easily fixed.
Comment From: jbrockmendel
if you want to make a specific issue of things to do on NaT that is fine. but pls don't mix issues.
Sure. Any preference over a new issue to list questions/todos as I find them vs renaming this one? I don't want to inundate you.