@@ -37,22 +37,18 @@ _nat_scalar_rules[Py_GE] = False
37
37
38
38
# ----------------------------------------------------------------------
39
39
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 ):
53
42
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
+
55
48
49
+ def _make_nat_func (func_name , doc ):
50
+ def f (*args , **kwargs ):
51
+ return NaT
56
52
f.__name__ = func_name
57
53
f.__doc__ = doc
58
54
return f
@@ -316,10 +312,9 @@ class NaTType(_NaT):
316
312
# These are the ones that can get their docstrings from datetime.
317
313
318
314
# 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
323
318
"""
324
319
Return the month name of the Timestamp with specified locale.
325
320
@@ -332,7 +327,7 @@ class NaTType(_NaT):
332
327
-------
333
328
month_name : string
334
329
""" )
335
- day_name = _make_missing_value_func (' day_name' , np.nan, # noqa:E128
330
+ day_name = _make_nan_func (' day_name' , # noqa:E128
336
331
"""
337
332
Return the day name of the Timestamp with specified locale.
338
333
@@ -346,7 +341,7 @@ class NaTType(_NaT):
346
341
day_name : string
347
342
""" )
348
343
# _nat_methods
349
- date = _make_missing_value_func (' date' , NaT, datetime.__doc__ )
344
+ date = _make_nat_func (' date' , datetime.date .__doc__ )
350
345
351
346
utctimetuple = _make_error_func(' utctimetuple' , datetime)
352
347
timetz = _make_error_func(' timetz' , datetime)
@@ -436,14 +431,14 @@ class NaTType(_NaT):
436
431
""" )
437
432
438
433
# _nat_methods
439
- to_pydatetime = _make_missing_value_func (' to_pydatetime' , NaT , # noqa:E128
434
+ to_pydatetime = _make_nat_func (' to_pydatetime' , # noqa:E128
440
435
"""
441
436
Convert a Timestamp object to a native Python datetime object.
442
437
443
438
If warn=True, issue a warning if nanoseconds is nonzero.
444
439
""" )
445
440
446
- now = _make_missing_value_func (' now' , NaT , # noqa:E128
441
+ now = _make_nat_func (' now' , # noqa:E128
447
442
"""
448
443
Timestamp.now(tz=None)
449
444
@@ -455,7 +450,7 @@ class NaTType(_NaT):
455
450
tz : str or timezone object, default None
456
451
Timezone to localize to
457
452
""" )
458
- today = _make_missing_value_func (' today' , NaT , # noqa:E128
453
+ today = _make_nat_func (' today' , # noqa:E128
459
454
"""
460
455
Timestamp.today(cls, tz=None)
461
456
@@ -468,7 +463,7 @@ class NaTType(_NaT):
468
463
tz : str or timezone object, default None
469
464
Timezone to localize to
470
465
""" )
471
- round = _make_missing_value_func (' round' , NaT , # noqa:E128
466
+ round = _make_nat_func (' round' , # noqa:E128
472
467
"""
473
468
Round the Timestamp to the specified resolution
474
469
@@ -484,15 +479,15 @@ class NaTType(_NaT):
484
479
------
485
480
ValueError if the freq cannot be converted
486
481
""" )
487
- floor = _make_missing_value_func (' floor' , NaT , # noqa:E128
482
+ floor = _make_nat_func (' floor' , # noqa:E128
488
483
"""
489
484
return a new Timestamp floored to this resolution
490
485
491
486
Parameters
492
487
----------
493
488
freq : a freq string indicating the flooring resolution
494
489
""" )
495
- ceil = _make_missing_value_func (' ceil' , NaT , # noqa:E128
490
+ ceil = _make_nat_func (' ceil' , # noqa:E128
496
491
"""
497
492
return a new Timestamp ceiled to this resolution
498
493
@@ -501,7 +496,7 @@ class NaTType(_NaT):
501
496
freq : a freq string indicating the ceiling resolution
502
497
""" )
503
498
504
- tz_convert = _make_missing_value_func (' tz_convert' , NaT , # noqa:E128
499
+ tz_convert = _make_nat_func (' tz_convert' , # noqa:E128
505
500
"""
506
501
Convert tz-aware Timestamp to another time zone.
507
502
@@ -520,7 +515,7 @@ class NaTType(_NaT):
520
515
TypeError
521
516
If Timestamp is tz-naive.
522
517
""" )
523
- tz_localize = _make_missing_value_func (' tz_localize' , NaT , # noqa:E128
518
+ tz_localize = _make_nat_func (' tz_localize' , # noqa:E128
524
519
"""
525
520
Convert naive Timestamp to local time zone, or remove
526
521
timezone from tz-aware Timestamp.
@@ -555,7 +550,7 @@ class NaTType(_NaT):
555
550
TypeError
556
551
If the Timestamp is tz-aware and tz is not None.
557
552
""" )
558
- replace = _make_missing_value_func (' replace' , NaT , # noqa:E128
553
+ replace = _make_nat_func (' replace' , # noqa:E128
559
554
"""
560
555
implements datetime.replace, handles nanoseconds
561
556
0 commit comments