Converting a numpy.datetime64 into DateTime?
- 主要言語
- Julia
- スター
- 1.5k
- フォーク
- 186
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
I load some data using Python's xarray, which result to datetime-vectors, for example:
```
julia> x = w["time"].values
PyObject array(['2000-01-01T00:00:00.000000000', '2000-02-01T00:00:00.000000000',
'2000-03-01T00:00:00.000000000', '2000-04-01T00:00:00.000000000',
'2000-05-01T00:00:00.000000000', '2000-06-01T00:00:00.000000000',
'2000-07-01T00:00:00.000000000', '2000-08-01T00:00:00.000000000',
'2000-09-01T00:00:00.000000000', '2000-10-01T00:00:00.000000000',
'2000-11-01T00:00:00.000000000', '2000-12-01T00:00:00.000000000',
'2001-01-01T00:00:00.000000000', '2001-02-01T00:00:00.000000000',
'2001-03-01T00:00:00.000000000', '2001-04-01T00:00:00.000000000',
.....
'2019-07-01T00:00:00.000000000', '2019-08-01T00:00:00.000000000',
'2019-09-01T00:00:00.000000000', '2019-10-01T00:00:00.000000000',
'2019-11-01T00:00:00.000000000', '2019-12-01T00:00:00.000000000',
'2020-01-01T00:00:00.000000000', '2020-02-01T00:00:00.000000000',
'2020-03-01T00:00:00.000000000', '2020-04-01T00:00:00.000000000',
'2020-05-01T00:00:00.000000000', '2020-06-01T00:00:00.000000000',
'2020-07-01T00:00:00.000000000', '2020-08-01T00:00:00.000000000',
'2020-09-01T00:00:00.000000000'], dtype='datetime64[ns]')
julia> y = x[1]
PyObject numpy.datetime64('2000-01-01T00:00:00.000000000')
```
The data are not automatically put into Julia form, which happens if the type of `w["dimension"]` is Float64 or Integer. But that's okay, I don't mind converting myself. The problem is, that is not possible either:
```
julia> DateTime(y)
ERROR: MethodError: no method matching Int64(::PyObject)
Closest candidates are:
Int64(::Union{Bool, Int32, Int64, UInt32, UInt64, UInt8, Int128, Int16, Int8, UInt128, UInt16}) at boot.jl:708
Int64(::Ptr) at boot.jl:718
Int64(::Float32) at float.jl:706
...
Stacktrace:
[1] DateTime(::PyObject, ::Int64, ::Int64, ::Int64, ::Int64, ::Int64, ::Int64, ::Dates.AMPM) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\Dates\src\types.jl:367 (repeats 2 times)
[2] top-level scope at none:1
```
I've tried other variants of date-related functions but it didn't work.
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
調査の方向性
リポジトリのファイルやテストは指定されていません。xarray/NumPy の datetime64 の例を Julia で再現し、その後、PyCall が NumPy のスカラーと配列の変換をどのように処理するかを調査してください。報告された datetime64 値が Julia の DateTime に変換されるか、サポートされている変換動作が明確にドキュメント化されれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- julia, numpy, python
- 領域
- data
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100