Skip to content

numpy.datetime64 precision cause dict indexing failure in index_data.py #1806

@GeorgeGuo1202

Description

@GeorgeGuo1202

🐛 Bug Description

ns precision numpy.datetime64 is equal to second precision
however when doing indexing of a dict keys, it will cause failure

numpy.datetime64('2017-01-04T00:00:00.000000000')==numpy.datetime64('2017-01-04T00:00:00')
Out[24]: True
self.index_map[numpy.datetime64('2017-01-04T00:00:00.000000000')]
Out[25]: 1
self.index_map[numpy.datetime64('2017-01-04T00:00:00')]
Traceback (most recent call last):
File "F:\work\env\py311\Lib\site-packages\IPython\core\interactiveshell.py", line 3508, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "", line 1, in
self.index_map[numpy.datetime64('2017-01-04T00:00:00')]
~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: numpy.datetime64('2017-01-04T00:00:00')

it occurs at qlib/qlib/utils/index_data.py, line 157:
try:
return self.index_map[self._convert_type(item)]
except IndexError as index_e:
raise KeyError(f"{item} can't be found in {self}") from index_e

maybe I did something wrong, hoping for help

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions