Skip to content

ENH: add 'asm8' to NaT #11816

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions pandas/tseries/tests/test_tslib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 4 additions & 4 deletions pandas/tslib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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 = <PyTypeObject*> Timestamp

Expand Down