File tree 3 files changed +20
-0
lines changed
3 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -63,6 +63,7 @@ Enhancements
63
63
- Paths beginning with ~ will now be expanded to begin with the user's home directory (:issue:`9066`)
64
64
- Added time interval selection in get_data_yahoo (:issue:`9071`)
65
65
- Added ``Series.str.slice_replace()``, which previously raised NotImplementedError (:issue:`8888`)
66
+ - Added ``Timestamp.to_datetime64()`` to complement ``Timedelta.to_timedelta64()`` (:issue:`9255`)
66
67
67
68
68
69
Performance
Original file line number Diff line number Diff line change @@ -136,6 +136,21 @@ def test_constructor_with_stringoffset(self):
136
136
self .assertEqual (repr (result ), expected_repr )
137
137
self .assertEqual (result , eval (repr (result )))
138
138
139
+ def test_conversion (self ):
140
+ # GH 9255
141
+ ts = Timestamp ('2000-01-01' )
142
+
143
+ result = ts .to_pydatetime ()
144
+ expected = datetime .datetime (2000 , 1 , 1 )
145
+ self .assertEqual (result , expected )
146
+ self .assertEqual (type (result ), type (expected ))
147
+
148
+ result = ts .to_datetime64 ()
149
+ expected = np .datetime64 (ts .value , 'ns' )
150
+ self .assertEqual (result , expected )
151
+ self .assertEqual (type (result ), type (expected ))
152
+ self .assertEqual (result .dtype , expected .dtype )
153
+
139
154
def test_repr (self ):
140
155
tm ._skip_if_no_pytz ()
141
156
tm ._skip_if_no_dateutil ()
Original file line number Diff line number Diff line change @@ -852,6 +852,10 @@ cdef class _Timestamp(datetime):
852
852
dts.hour, dts.min, dts.sec,
853
853
dts.us, ts.tzinfo)
854
854
855
+ cpdef to_datetime64(self ):
856
+ """ Returns a numpy.datetime64 object with 'ns' precision """
857
+ return np.datetime64(self .value, ' ns' )
858
+
855
859
def __add__ (self , other ):
856
860
cdef int64_t other_int
857
861
You can’t perform that action at this time.
0 commit comments