Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Any way to change datetime64 resolution? #6741

Copy link
Copy link
Closed
@altaurog

Description

@altaurog
Issue body actions

xref to #7307

Converting from datetime64[ns] to datetime64[m] is disallowed, as mentioned in issue #3416, apparently because of a numpy bug. It looks to me like numpy does this correctly, however. It would be nice if this could work without resorting to raw numpy arrays:

In [89]: s = pd.Series(['20140330','19740821'])
In [90]: pd.to_datetime(s)
Out[90]: 
0   2014-03-30
1   1974-08-21
dtype: datetime64[ns]
In [91]: pd.to_datetime(s).values
Out[91]: 
array(['2014-03-30T03:00:00.000000000+0300',
       '1974-08-21T03:00:00.000000000+0300'], dtype='datetime64[ns]')
In [92]: pd.to_datetime(s).values.astype('datetime64[h]')
Out[92]: array(['2014-03-30T03+0300', '1974-08-21T03+0300'], dtype='datetime64[h]')

My other workaround, which is slightly less clumsy, is do just convert manually, since casting to int64 is permitted:

In [103]: pd.to_datetime(s).astype('int64').div(6e10) # minutes since epoch

But it'd be nicer not to have to do all that.

In [93]: pd.show_versions()

INSTALLED VERSIONS
------------------
commit: None
python: 2.7.3.final.0
python-bits: 64
OS: Linux
OS-release: 3.2.0-4-amd64
machine: x86_64
processor: 
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8

pandas: 0.13.1
Cython: 0.20
numpy: 1.8.0
scipy: None
statsmodels: None
IPython: 1.2.1
sphinx: 1.1.3
patsy: None
scikits.timeseries: None
dateutil: 1.5
pytz: 2012c
bottleneck: 0.8.0
tables: 3.1.0
numexpr: 2.3.1
matplotlib: 1.3.1
openpyxl: None
xlrd: None
xlwt: 0.7.4
xlsxwriter: None
sqlalchemy: None
lxml: None
bs4: None
html5lib: 0.999
bq: None
apiclient: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.