@@ -37,22 +37,18 @@ _nat_scalar_rules[Py_GE] = False
3737
3838# ----------------------------------------------------------------------
3939
40- def _make_missing_value_func (func_name , missing_value , doc ):
41- """ Generate function that returns a missing value
42-
43- Parameters
44- ----------
45- func_name : string
46- missing_value : nan value
47- doc: string
48-
49- Returns
50- -------
51- f : function
52- """
40+
41+ def _make_nan_func (func_name , doc ):
5342 def f (*args , **kwargs ):
54- return missing_value
43+ return np.nan
44+ f.__name__ = func_name
45+ f.__doc__ = doc
46+ return f
47+
5548
49+ def _make_nat_func (func_name , doc ):
50+ def f (*args , **kwargs ):
51+ return NaT
5652 f.__name__ = func_name
5753 f.__doc__ = doc
5854 return f
@@ -316,10 +312,9 @@ class NaTType(_NaT):
316312 # These are the ones that can get their docstrings from datetime.
317313
318314 # nan methods
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
315+ weekday = _make_nan_func(' weekday' , datetime.weekday.__doc__ )
316+ isoweekday = _make_nan_func(' isoweekday' , datetime.isoweekday.__doc__ )
317+ month_name = _make_nan_func(' month_name' , # noqa:E128
323318 """
324319 Return the month name of the Timestamp with specified locale.
325320
@@ -332,7 +327,7 @@ class NaTType(_NaT):
332327 -------
333328 month_name : string
334329 """ )
335- day_name = _make_missing_value_func (' day_name' , np.nan, # noqa:E128
330+ day_name = _make_nan_func (' day_name' , # noqa:E128
336331 """
337332 Return the day name of the Timestamp with specified locale.
338333
@@ -346,7 +341,7 @@ class NaTType(_NaT):
346341 day_name : string
347342 """ )
348343 # _nat_methods
349- date = _make_missing_value_func (' date' , NaT, datetime.__doc__ )
344+ date = _make_nat_func (' date' , datetime.date .__doc__ )
350345
351346 utctimetuple = _make_error_func(' utctimetuple' , datetime)
352347 timetz = _make_error_func(' timetz' , datetime)
@@ -436,14 +431,14 @@ class NaTType(_NaT):
436431 """ )
437432
438433 # _nat_methods
439- to_pydatetime = _make_missing_value_func (' to_pydatetime' , NaT , # noqa:E128
434+ to_pydatetime = _make_nat_func (' to_pydatetime' , # noqa:E128
440435 """
441436 Convert a Timestamp object to a native Python datetime object.
442437
443438 If warn=True, issue a warning if nanoseconds is nonzero.
444439 """ )
445440
446- now = _make_missing_value_func (' now' , NaT , # noqa:E128
441+ now = _make_nat_func (' now' , # noqa:E128
447442 """
448443 Timestamp.now(tz=None)
449444
@@ -455,7 +450,7 @@ class NaTType(_NaT):
455450 tz : str or timezone object, default None
456451 Timezone to localize to
457452 """ )
458- today = _make_missing_value_func (' today' , NaT , # noqa:E128
453+ today = _make_nat_func (' today' , # noqa:E128
459454 """
460455 Timestamp.today(cls, tz=None)
461456
@@ -468,7 +463,7 @@ class NaTType(_NaT):
468463 tz : str or timezone object, default None
469464 Timezone to localize to
470465 """ )
471- round = _make_missing_value_func (' round' , NaT , # noqa:E128
466+ round = _make_nat_func (' round' , # noqa:E128
472467 """
473468 Round the Timestamp to the specified resolution
474469
@@ -484,15 +479,15 @@ class NaTType(_NaT):
484479 ------
485480 ValueError if the freq cannot be converted
486481 """ )
487- floor = _make_missing_value_func (' floor' , NaT , # noqa:E128
482+ floor = _make_nat_func (' floor' , # noqa:E128
488483 """
489484 return a new Timestamp floored to this resolution
490485
491486 Parameters
492487 ----------
493488 freq : a freq string indicating the flooring resolution
494489 """ )
495- ceil = _make_missing_value_func (' ceil' , NaT , # noqa:E128
490+ ceil = _make_nat_func (' ceil' , # noqa:E128
496491 """
497492 return a new Timestamp ceiled to this resolution
498493
@@ -501,7 +496,7 @@ class NaTType(_NaT):
501496 freq : a freq string indicating the ceiling resolution
502497 """ )
503498
504- tz_convert = _make_missing_value_func (' tz_convert' , NaT , # noqa:E128
499+ tz_convert = _make_nat_func (' tz_convert' , # noqa:E128
505500 """
506501 Convert tz-aware Timestamp to another time zone.
507502
@@ -520,7 +515,7 @@ class NaTType(_NaT):
520515 TypeError
521516 If Timestamp is tz-naive.
522517 """ )
523- tz_localize = _make_missing_value_func (' tz_localize' , NaT , # noqa:E128
518+ tz_localize = _make_nat_func (' tz_localize' , # noqa:E128
524519 """
525520 Convert naive Timestamp to local time zone, or remove
526521 timezone from tz-aware Timestamp.
@@ -555,7 +550,7 @@ class NaTType(_NaT):
555550 TypeError
556551 If the Timestamp is tz-aware and tz is not None.
557552 """ )
558- replace = _make_missing_value_func (' replace' , NaT , # noqa:E128
553+ replace = _make_nat_func (' replace' , # noqa:E128
559554 """
560555 implements datetime.replace, handles nanoseconds
561556
0 commit comments