Correspondence to ‘cannot encode object: num, of type: <class’ numpy.int64'> `in Pymongo error

Overview

As the title says

Background

I stumbled upon trying to ʻinsert` a Dict using Pymongo that obediently incorporated a Dict type value created by calculation processing via Numpy developed by another person into the value.

Why didn't you understand?

Dict structurally

score = { 
  'score1' = 1,
  'score2' = 2,
  'score3': {'score3_1':10}
}

Since the value of score_3_1 was Numpy when it had a structure like this, I couldn't tell if it was Numpy by looking at the value type of score.

Correspondence

If you cast the numerical value existing in Dict to a type such as ʻint () `, it's OK!

comment

The error didn't say the wrong thing.

Recommended Posts

Correspondence to ‘cannot encode object: num, of type: <class’ numpy.int64'> `in Pymongo error
Convert / return class object to JSON format in Python
"Type Error: Unrecognized value type: <class'str'>" in to_datetime of pandas