Skip to content

Casting a NaT with a timedelta64or datetime64 to float64 return big negative number  #8449

Open

Description

@will133

I'm using numpy 1.11.2 on Linux and here is what I get:

In [1]: import numpy

In [2]: x = numpy.array([3, None], 'm8[D]')

In [3]: x.astype('float64')
array([  3.00000000e+00,  -9.22337204e+18])

This behavior seems to be the same for datetime64 as well.

IMHO, this causes a potentially dangerous problem where the wrong calculation is returned silently and the negative most int64 is used instead of nan. For example, if you want to do a calculation in dates and then convert this to float to calculate the number of years (approximately), you can't just do an arr.astype('float64') / 365 since the NaT to nan is not handled correctly.

Activity

  1. mattip commented on Sep 4, 2018

    @mattip
    Member

    The inverse of issue #8780

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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