Skip to content

Serialize np.float64 as float #257

@mzat-msft

Description

@mzat-msft

On my machine np.float64 are the same as float, so I would expect that they are serialized in the same way. However, this is not the case as the logic in

def serialize_object(self, attr, **kwargs):
infer the type of the object's attribute using type rather than isinstance.

Do you think it makes sense to treat classes that are subclasses of basic types as basic types in the serialization process?

Here is a minimal working example of what I'm referring to. Note that np-float is cast to a str instead of a float.

import msrest.serialization
import numpy as np


class ModelWithNpFloat(msrest.serialization.Model):
    _attribute_map = {
        "state": {"key": "state", "type": "object"},
    }

    def __init__(self, state):
        self.state = state


model = ModelWithNpFloat(state={'np-float': np.float64(100)})
print(model.serialize())  # {'state': {'np-float': '100.0'}}

Metadata

Metadata

Assignees

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