JuliaPy / JuliaPy/PyCall.jl

Converting a numpy.datetime64 into DateTime?

Abierto
#858 2 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Julia
Estrellas
1.5k
Forks
186
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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.

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Línea de trabajo

No se nombran archivos ni pruebas del repositorio. Reproduce el ejemplo de datetime64 de xarray/NumPy en Julia y, después, inspecciona cómo PyCall gestiona las conversiones de escalares y arrays de NumPy. Se considera terminado cuando el valor datetime64 notificado se convierte en un DateTime de Julia, o cuando el comportamiento de conversión compatible está claramente documentado.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
julia, numpy, python
Área
data
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.