11# -*- coding: utf-8 -*-
22# cython: profile=False
3- import warnings
43
54from cpython cimport (
65 PyFloat_Check, PyComplex_Check,
@@ -38,30 +37,24 @@ _nat_scalar_rules[Py_GE] = False
3837
3938# ----------------------------------------------------------------------
4039
40+ def _make_missing_value_func (func_name , missing_value , doc ):
41+ """ Generate function that returns a missing value
4142
42- def _make_nan_func (func_name , cls ):
43- def f (*args , **kwargs ):
44- return np.nan
43+ Parameters
44+ ----------
45+ func_name : string
46+ missing_value : nan value
47+ doc: string
4548
46- f.__name__ = func_name
47- if isinstance (cls , str ):
48- # passed the literal docstring directly
49- f.__doc__ = cls
50- else :
51- f.__doc__ = getattr (cls , func_name).__doc__
52- return f
53-
54-
55- def _make_nat_func (func_name , cls ):
49+ Returns
50+ -------
51+ f : function
52+ """
5653 def f (*args , **kwargs ):
57- return NaT
54+ return missing_value
5855
5956 f.__name__ = func_name
60- if isinstance (cls , str ):
61- # passed the literal docstring directly
62- f.__doc__ = cls
63- else :
64- f.__doc__ = getattr (cls , func_name).__doc__
57+ f.__doc__ = doc
6558 return f
6659
6760
@@ -323,9 +316,10 @@ class NaTType(_NaT):
323316 # These are the ones that can get their docstrings from datetime.
324317
325318 # nan methods
326- weekday = _make_nan_func(' weekday' , datetime)
327- isoweekday = _make_nan_func(' isoweekday' , datetime)
328- month_name = _make_nan_func(' month_name' , # noqa:E128
319+ weekday = _make_missing_value_func(' weekday' , np.nan, datetime.__doc__ )
320+ isoweekday = _make_missing_value_func(' isoweekday' , np.nan,
321+ datetime.__doc__ )
322+ month_name = _make_missing_value_func(' month_name' , np.nan, # noqa:E128
329323 """
330324 Return the month name of the Timestamp with specified locale.
331325
@@ -338,7 +332,7 @@ class NaTType(_NaT):
338332 -------
339333 month_name : string
340334 """ )
341- day_name = _make_nan_func (' day_name' , # noqa:E128
335+ day_name = _make_missing_value_func (' day_name' , np.nan , # noqa:E128
342336 """
343337 Return the day name of the Timestamp with specified locale.
344338
@@ -352,7 +346,7 @@ class NaTType(_NaT):
352346 day_name : string
353347 """ )
354348 # _nat_methods
355- date = _make_nat_func (' date' , datetime)
349+ date = _make_missing_value_func (' date' , NaT, datetime. __doc__ )
356350
357351 utctimetuple = _make_error_func(' utctimetuple' , datetime)
358352 timetz = _make_error_func(' timetz' , datetime)
@@ -442,14 +436,14 @@ class NaTType(_NaT):
442436 """ )
443437
444438 # _nat_methods
445- to_pydatetime = _make_nat_func (' to_pydatetime' , # noqa:E128
439+ to_pydatetime = _make_missing_value_func (' to_pydatetime' , NaT , # noqa:E128
446440 """
447441 Convert a Timestamp object to a native Python datetime object.
448442
449443 If warn=True, issue a warning if nanoseconds is nonzero.
450444 """ )
451445
452- now = _make_nat_func (' now' , # noqa:E128
446+ now = _make_missing_value_func (' now' , NaT , # noqa:E128
453447 """
454448 Timestamp.now(tz=None)
455449
@@ -461,7 +455,7 @@ class NaTType(_NaT):
461455 tz : str or timezone object, default None
462456 Timezone to localize to
463457 """ )
464- today = _make_nat_func (' today' , # noqa:E128
458+ today = _make_missing_value_func (' today' , NaT , # noqa:E128
465459 """
466460 Timestamp.today(cls, tz=None)
467461
@@ -474,7 +468,7 @@ class NaTType(_NaT):
474468 tz : str or timezone object, default None
475469 Timezone to localize to
476470 """ )
477- round = _make_nat_func (' round' , # noqa:E128
471+ round = _make_missing_value_func (' round' , NaT , # noqa:E128
478472 """
479473 Round the Timestamp to the specified resolution
480474
@@ -490,15 +484,15 @@ class NaTType(_NaT):
490484 ------
491485 ValueError if the freq cannot be converted
492486 """ )
493- floor = _make_nat_func (' floor' , # noqa:E128
487+ floor = _make_missing_value_func (' floor' , NaT , # noqa:E128
494488 """
495489 return a new Timestamp floored to this resolution
496490
497491 Parameters
498492 ----------
499493 freq : a freq string indicating the flooring resolution
500494 """ )
501- ceil = _make_nat_func (' ceil' , # noqa:E128
495+ ceil = _make_missing_value_func (' ceil' , NaT , # noqa:E128
502496 """
503497 return a new Timestamp ceiled to this resolution
504498
@@ -507,7 +501,7 @@ class NaTType(_NaT):
507501 freq : a freq string indicating the ceiling resolution
508502 """ )
509503
510- tz_convert = _make_nat_func (' tz_convert' , # noqa:E128
504+ tz_convert = _make_missing_value_func (' tz_convert' , NaT , # noqa:E128
511505 """
512506 Convert tz-aware Timestamp to another time zone.
513507
@@ -526,7 +520,7 @@ class NaTType(_NaT):
526520 TypeError
527521 If Timestamp is tz-naive.
528522 """ )
529- tz_localize = _make_nat_func (' tz_localize' , # noqa:E128
523+ tz_localize = _make_missing_value_func (' tz_localize' , NaT , # noqa:E128
530524 """
531525 Convert naive Timestamp to local time zone, or remove
532526 timezone from tz-aware Timestamp.
@@ -561,7 +555,7 @@ class NaTType(_NaT):
561555 TypeError
562556 If the Timestamp is tz-aware and tz is not None.
563557 """ )
564- replace = _make_nat_func (' replace' , # noqa:E128
558+ replace = _make_missing_value_func (' replace' , NaT , # noqa:E128
565559 """
566560 implements datetime.replace, handles nanoseconds
567561
0 commit comments