numpy.datetime64可以处理的最大时间戳是多少? [英] What is the maximum timestamp numpy.datetime64 can handle?

查看:84
本文介绍了numpy.datetime64可以处理的最大时间戳是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 datetime 转换为 numpy.datetime64 ,但是以下情况失败了:

I'm trying to convert datetime to numpy.datetime64 but the following case fails:

>>> import numpy as np
>>> from datetime import datetime
>>> np.datetime64(datetime.max)
OSError: Failed to use 'localtime_s' to convert to a local time

我认为 datetime46 无法处理如此遥远的时间戳.

I presume that datetime46 can't handle such far-dated timestamps.

那么 datetime46 可以处理的最大时间戳是多少?

So what is the maximum timestamp that datetime46 can handle?

推荐答案

取决于 np.datetime64 对象的指定单位是什么(根据

Depends on what the specified unit of your np.datetime64 object is (according to the numpy docs). Since you have given a timestamp with microseconds the allowed range is [290301 BC, 294241 AD].

这回答了您的问题,但我认为另一个未曾说过的问题是为什么它引发异常:

This answered your question but I think the unspoken other question is why it throws an Exception:

我遇到相同的错误(使用Windows),并尝试了有效的 a = np.datetime64(datetime.max).因此,我怀疑问题不是 NOT np.datetime64 跨度(因为可以创建这样的 datetime 有效),但是 __ repr __ 在某种程度上需要操作系统,并且操作系统可能会根据您的情况对其进行限制.因此,请检查操作系统的最大本地时间是多少,之后的每个日期时间,您仍然可以使用 np.datetime64 对象,但无法在屏幕上打印它们.:-)

I'm facing the same error (using Windows) and I tried a=np.datetime64(datetime.max) which works. Therefore I suspect the problem is NOT the np.datetime64 span (because creating such a datetime works) but that the __repr__ requires the OS in some way and probably the OS limits it in your case. So check what's the maximum localtime of your OS and for every datetime after that you can still work with the np.datetime64 objects but cannot print them on screen. :-)

这篇关于numpy.datetime64可以处理的最大时间戳是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆