datajoint / datajoint-docs-original

https://docs.datajoint.org
Other
2 stars 13 forks source link

improve documentation on fractional time seconds in timestamp/datetime #256

Open ixcat opened 3 years ago

ixcat commented 3 years ago

more audit needed for full coverage across py/matlab; that said, it appears that at least for dj python, one needs to 'timestamp(N)' to get access to sub-second precision

see also: https://dev.mysql.com/doc/refman/5.7/en/fractional-seconds.html

no fractional seconds:

>>> @schema
... class TestStamp(dj.Manual):
...     definition = '''
...     ts_id: int
...     ---
...     ts_dat: datetime
...     '''
... 
>>> TestStamp().insert1((0, datetime.now()))
>>> TestStamp().fetch()
array([(0, datetime.datetime(2021, 2, 16, 10, 18, 57))],
      dtype=[('ts_id', '<i8'), ('ts_dat', 'O')])

with fractional seconds:

>>> @schema
... class TestOtherStamp(dj.Manual):
...     definition = '''
...     ts_id: int
...     ---
...     ts_dat: datetime(6)
...     '''
... 
>>> TestOtherStamp.insert1((0, datetime.now()))
>>> TestOtherStamp()
*ts_id    ts_dat        
+-------+ +------------+
0         2021-02-16 10:
 (Total: 1)

>>> TestOtherStamp().fetch()
array([(0, datetime.datetime(2021, 2, 16, 10, 30, 13, 223264))],
      dtype=[('ts_id', '<i8'), ('ts_dat', 'O')])