|
1 | 1 | # cython: profile=False
|
2 | 2 |
|
| 3 | +import warnings |
| 4 | + |
3 | 5 | cimport numpy as np
|
4 | 6 | from numpy cimport (int8_t, int32_t, int64_t, import_array, ndarray,
|
5 | 7 | NPY_INT64, NPY_DATETIME, NPY_TIMEDELTA)
|
@@ -637,22 +639,6 @@ class Timestamp(_Timestamp):
|
637 | 639 | return Timestamp(datetime.replace(self, **kwds),
|
638 | 640 | freq=self.freq)
|
639 | 641 |
|
640 |
| - def to_pydatetime(self, warn=True): |
641 |
| - """ |
642 |
| - If warn=True, issue warning if nanoseconds is nonzero |
643 |
| - """ |
644 |
| - cdef: |
645 |
| - pandas_datetimestruct dts |
646 |
| - _TSObject ts |
647 |
| - |
648 |
| - if self.nanosecond != 0 and warn: |
649 |
| - print 'Warning: discarding nonzero nanoseconds' |
650 |
| - ts = convert_to_tsobject(self, self.tzinfo, None, 0, 0) |
651 |
| - |
652 |
| - return datetime(ts.dts.year, ts.dts.month, ts.dts.day, |
653 |
| - ts.dts.hour, ts.dts.min, ts.dts.sec, |
654 |
| - ts.dts.us, ts.tzinfo) |
655 |
| - |
656 | 642 | def isoformat(self, sep='T'):
|
657 | 643 | base = super(_Timestamp, self).isoformat(sep=sep)
|
658 | 644 | if self.nanosecond == 0:
|
@@ -986,7 +972,7 @@ cdef class _Timestamp(datetime):
|
986 | 972 | ots = other
|
987 | 973 | elif isinstance(other, datetime):
|
988 | 974 | if self.nanosecond == 0:
|
989 |
| - val = self.to_datetime() |
| 975 | + val = self.to_pydatetime() |
990 | 976 | return PyObject_RichCompareBool(val, other, op)
|
991 | 977 |
|
992 | 978 | try:
|
@@ -1048,7 +1034,7 @@ cdef class _Timestamp(datetime):
|
1048 | 1034 |
|
1049 | 1035 | cdef bint _compare_outside_nanorange(_Timestamp self, datetime other,
|
1050 | 1036 | int op) except -1:
|
1051 |
| - cdef datetime dtval = self.to_datetime() |
| 1037 | + cdef datetime dtval = self.to_pydatetime(warn=False) |
1052 | 1038 |
|
1053 | 1039 | self._assert_tzawareness_compat(other)
|
1054 | 1040 |
|
@@ -1078,9 +1064,27 @@ cdef class _Timestamp(datetime):
|
1078 | 1064 | raise TypeError('Cannot compare tz-naive and tz-aware timestamps')
|
1079 | 1065 |
|
1080 | 1066 | cpdef datetime to_datetime(_Timestamp self):
|
| 1067 | + """ |
| 1068 | + DEPRECATED: use :meth:`to_pydatetime` instead. |
| 1069 | +
|
| 1070 | + Convert a Timestamp object to a native Python datetime object. |
| 1071 | + """ |
| 1072 | + warnings.warn("to_datetime is deprecated. Use self.to_pydatetime()", |
| 1073 | + FutureWarning, stacklevel=2) |
| 1074 | + return self.to_pydatetime(warn=False) |
| 1075 | + |
| 1076 | + cpdef datetime to_pydatetime(_Timestamp self, warn=True): |
| 1077 | + """ |
| 1078 | + Convert a Timestamp object to a native Python datetime object. |
| 1079 | +
|
| 1080 | + If warn=True, issue a warning if nanoseconds is nonzero. |
| 1081 | + """ |
1081 | 1082 | cdef:
|
1082 | 1083 | pandas_datetimestruct dts
|
1083 | 1084 | _TSObject ts
|
| 1085 | + |
| 1086 | + if self.nanosecond != 0 and warn: |
| 1087 | + print 'Warning: discarding nonzero nanoseconds' |
1084 | 1088 | ts = convert_to_tsobject(self, self.tzinfo, None, 0, 0)
|
1085 | 1089 | dts = ts.dts
|
1086 | 1090 | return datetime(dts.year, dts.month, dts.day,
|
|
0 commit comments