1
1
# -*- coding: utf-8 -*-
2
2
# cython: profile=False
3
- import warnings
4
3
5
4
from cpython cimport (
6
5
PyFloat_Check, PyComplex_Check,
@@ -38,30 +37,24 @@ _nat_scalar_rules[Py_GE] = False
38
37
39
38
# ----------------------------------------------------------------------
40
39
40
+ def _make_missing_value_func (func_name , missing_value , doc ):
41
+ """ Generate function that returns a missing value
41
42
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
45
48
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
+ """
56
53
def f (*args , **kwargs ):
57
- return NaT
54
+ return missing_value
58
55
59
56
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
65
58
return f
66
59
67
60
@@ -323,9 +316,10 @@ class NaTType(_NaT):
323
316
# These are the ones that can get their docstrings from datetime.
324
317
325
318
# 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
329
323
"""
330
324
Return the month name of the Timestamp with specified locale.
331
325
@@ -338,7 +332,7 @@ class NaTType(_NaT):
338
332
-------
339
333
month_name : string
340
334
""" )
341
- day_name = _make_nan_func (' day_name' , # noqa:E128
335
+ day_name = _make_missing_value_func (' day_name' , np.nan , # noqa:E128
342
336
"""
343
337
Return the day name of the Timestamp with specified locale.
344
338
@@ -352,7 +346,7 @@ class NaTType(_NaT):
352
346
day_name : string
353
347
""" )
354
348
# _nat_methods
355
- date = _make_nat_func (' date' , datetime)
349
+ date = _make_missing_value_func (' date' , NaT, datetime. __doc__ )
356
350
357
351
utctimetuple = _make_error_func(' utctimetuple' , datetime)
358
352
timetz = _make_error_func(' timetz' , datetime)
@@ -442,14 +436,14 @@ class NaTType(_NaT):
442
436
""" )
443
437
444
438
# _nat_methods
445
- to_pydatetime = _make_nat_func (' to_pydatetime' , # noqa:E128
439
+ to_pydatetime = _make_missing_value_func (' to_pydatetime' , NaT , # noqa:E128
446
440
"""
447
441
Convert a Timestamp object to a native Python datetime object.
448
442
449
443
If warn=True, issue a warning if nanoseconds is nonzero.
450
444
""" )
451
445
452
- now = _make_nat_func (' now' , # noqa:E128
446
+ now = _make_missing_value_func (' now' , NaT , # noqa:E128
453
447
"""
454
448
Timestamp.now(tz=None)
455
449
@@ -461,7 +455,7 @@ class NaTType(_NaT):
461
455
tz : str or timezone object, default None
462
456
Timezone to localize to
463
457
""" )
464
- today = _make_nat_func (' today' , # noqa:E128
458
+ today = _make_missing_value_func (' today' , NaT , # noqa:E128
465
459
"""
466
460
Timestamp.today(cls, tz=None)
467
461
@@ -474,7 +468,7 @@ class NaTType(_NaT):
474
468
tz : str or timezone object, default None
475
469
Timezone to localize to
476
470
""" )
477
- round = _make_nat_func (' round' , # noqa:E128
471
+ round = _make_missing_value_func (' round' , NaT , # noqa:E128
478
472
"""
479
473
Round the Timestamp to the specified resolution
480
474
@@ -490,15 +484,15 @@ class NaTType(_NaT):
490
484
------
491
485
ValueError if the freq cannot be converted
492
486
""" )
493
- floor = _make_nat_func (' floor' , # noqa:E128
487
+ floor = _make_missing_value_func (' floor' , NaT , # noqa:E128
494
488
"""
495
489
return a new Timestamp floored to this resolution
496
490
497
491
Parameters
498
492
----------
499
493
freq : a freq string indicating the flooring resolution
500
494
""" )
501
- ceil = _make_nat_func (' ceil' , # noqa:E128
495
+ ceil = _make_missing_value_func (' ceil' , NaT , # noqa:E128
502
496
"""
503
497
return a new Timestamp ceiled to this resolution
504
498
@@ -507,7 +501,7 @@ class NaTType(_NaT):
507
501
freq : a freq string indicating the ceiling resolution
508
502
""" )
509
503
510
- tz_convert = _make_nat_func (' tz_convert' , # noqa:E128
504
+ tz_convert = _make_missing_value_func (' tz_convert' , NaT , # noqa:E128
511
505
"""
512
506
Convert tz-aware Timestamp to another time zone.
513
507
@@ -526,7 +520,7 @@ class NaTType(_NaT):
526
520
TypeError
527
521
If Timestamp is tz-naive.
528
522
""" )
529
- tz_localize = _make_nat_func (' tz_localize' , # noqa:E128
523
+ tz_localize = _make_missing_value_func (' tz_localize' , NaT , # noqa:E128
530
524
"""
531
525
Convert naive Timestamp to local time zone, or remove
532
526
timezone from tz-aware Timestamp.
@@ -561,7 +555,7 @@ class NaTType(_NaT):
561
555
TypeError
562
556
If the Timestamp is tz-aware and tz is not None.
563
557
""" )
564
- replace = _make_nat_func (' replace' , # noqa:E128
558
+ replace = _make_missing_value_func (' replace' , NaT , # noqa:E128
565
559
"""
566
560
implements datetime.replace, handles nanoseconds
567
561
0 commit comments