diff --git a/pandas/tseries/tests/test_tslib.py b/pandas/tseries/tests/test_tslib.py index 4fe136fceb671..679ee340f72bd 100644 --- a/pandas/tseries/tests/test_tslib.py +++ b/pandas/tseries/tests/test_tslib.py @@ -388,6 +388,17 @@ def test_today(self): self.assertTrue(abs(ts_from_string_tz.tz_localize(None) - ts_from_method_tz.tz_localize(None)) < delta) + def test_asm8(self): + np.random.seed(7960929) + ns = np.random.randint( + Timestamp.min.value, + Timestamp.max.value, + 1000, + ) + for n in ns: + self.assertEqual(Timestamp(n).asm8, np.datetime64(int(n), 'ns'), n) + self.assertEqual(Timestamp('nat').asm8, np.datetime64('nat', 'ns')) + def test_fields(self): def check(value, equal): diff --git a/pandas/tslib.pyx b/pandas/tslib.pyx index 84d0cc61be8e6..d1bc8025ba109 100644 --- a/pandas/tslib.pyx +++ b/pandas/tslib.pyx @@ -446,10 +446,6 @@ class Timestamp(_Timestamp): def freqstr(self): return getattr(self.offset, 'freqstr', self.offset) - @property - def asm8(self): - return np.int64(self.value).view('M8[ns]') - @property def is_month_start(self): return self._get_start_end_field('is_month_start') @@ -1063,6 +1059,10 @@ cdef class _Timestamp(datetime): out = get_start_end_field(np.array([self.value], dtype=np.int64), field, freqstr, month_kw) return out[0] + property asm8: + def __get__(self): + return np.datetime64(self.value, 'ns') + cdef PyTypeObject* ts_type = Timestamp