8000 Timedelta does not allow assignment from float · Issue #4440 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

Timedelta does not allow assignment from float #4440

@seberg

Description

@seberg

When trying gh-4434, I ran into a force-cast difference between timedelta force casting and timedelta item assignment. There is also a discrepancy for float64 vs. python floats:

In [12]: np.array(3.).astype('timedelta64[D]')
Out[12]: array(datetime.timedelta(3), dtype='timedelta64[D]')

In [13]: np.array(3., dtype='timedelta64[D]')
ValueError: Could not convert object to NumPy timedelta

and:

In [17]: np.empty(1, dtype='timedelta64[D]')[[0]] = np.float64(3.)

In [18]: np.empty(1, dtype='timedelta64[D]')[0] = np.float64(3.)
ValueError: Could not convert object to NumPy timedelta

I could easily hack around this by adding an ellipsis, but this all seems a bit weird...

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0