Skip to content

numpy.datetime64[ns] support #78

@maben-mw

Description

@maben-mw

I am trying to work with numpy.datetime64[ns], but the following:

import numpy
from inference_schema.parameter_types.numpy_parameter_type import NumpyParameterType
from inference_schema.schema_decorators import input_schema

data = numpy.array(["2023-06-06"],'datetime64[ns]')
schema = NumpyParameterType(data)

@input_schema("foo",schema)
def foo():
    pass

Throws:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/tmp/testenv/lib/python3.10/site-packages/inference_schema/schema_decorators.py", line 41, in input_schema
    swagger_schema = {param_name: param_type.input_to_swagger()}
  File "/tmp/testenv/lib/python3.10/site-packages/inference_schema/parameter_types/numpy_parameter_type.py", line 99, in input_to_swagger
    swagger_schema['example'] = self._get_swagger_sample(self.sample_input, items_count, swagger_schema['items'])
  File "/tmp/testenv/lib/python3.10/site-packages/inference_schema/parameter_types/abstract_parameter_type.py", line 88, in _get_swagger_sample
    item_sample = cls._get_data_record_swagger_sample(
  File "/tmp/testenv/lib/python3.10/site-packages/inference_schema/parameter_types/abstract_parameter_type.py", line 127, in _get_data_record_swagger_sample
    sample_swag = cls._timestamp_item_to_string(data_item)
  File "/tmp/testenv/lib/python3.10/site-packages/inference_schema/parameter_types/abstract_parameter_type.py", line 76, in _timestamp_item_to_string
    return cls._datetime_item_to_string(date_item)
  File "/tmp/testenv/lib/python3.10/site-packages/inference_schema/parameter_types/abstract_parameter_type.py", line 82, in _datetime_item_to_string
    return date_item.astype(dt.datetime).strftime("%Y-%m-%d %H:%M:%S,%f")
AttributeError: 'int' object has no attribute 'strftime'

Interestingly datetime64[us] does appear to work fine, but datetime64[ns] does not.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions