Skip to content

Commit def7462

Browse files
committed
Merge pull request #11816 from llllllllll/nat-as-mate
ENH: add 'asm8' to NaT
2 parents a7669d0 + 8a1e9aa commit def7462

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

pandas/tseries/tests/test_tslib.py

+11
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,17 @@ def test_today(self):
388388
self.assertTrue(abs(ts_from_string_tz.tz_localize(None)
389389
- ts_from_method_tz.tz_localize(None)) < delta)
390390

391+
def test_asm8(self):
392+
np.random.seed(7960929)
393+
ns = np.random.randint(
394+
Timestamp.min.value,
395+
Timestamp.max.value,
396+
1000,
397+
)
398+
for n in ns:
399+
self.assertEqual(Timestamp(n).asm8, np.datetime64(int(n), 'ns'), n)
400+
self.assertEqual(Timestamp('nat').asm8, np.datetime64('nat', 'ns'))
401+
391402
def test_fields(self):
392403

393404
def check(value, equal):

pandas/tslib.pyx

+4-4
Original file line numberDiff line numberDiff line change
@@ -446,10 +446,6 @@ class Timestamp(_Timestamp):
446446
def freqstr(self):
447447
return getattr(self.offset, 'freqstr', self.offset)
448448

449-
@property
450-
def asm8(self):
451-
return np.int64(self.value).view('M8[ns]')
452-
453449
@property
454450
def is_month_start(self):
455451
return self._get_start_end_field('is_month_start')
@@ -1063,6 +1059,10 @@ cdef class _Timestamp(datetime):
10631059
out = get_start_end_field(np.array([self.value], dtype=np.int64), field, freqstr, month_kw)
10641060
return out[0]
10651061

1062+
property asm8:
1063+
def __get__(self):
1064+
return np.datetime64(self.value, 'ns')
1065+
10661066

10671067
cdef PyTypeObject* ts_type = <PyTypeObject*> Timestamp
10681068

0 commit comments

Comments
 (0)