0

I am using a recarray loader which takes a dict of values as an argument. The string type is never passed to the array, yet clearly visible when creating the array:

My loader class:

import numpy as np

class Loader(np.recarray):
    def __new__(_, datas):
        obj = None

        results = [[],[]]
        for key, value in datas.items():
            print(type(value), value)
            results[0].append((key, type(value)))
            results[1].append(value)

        obj = np.array(tuple(results[1]), dtype=np.dtype(results[0]))

        return obj.view(np.recarray)

My test example

from communs.datas.Loader import Loader

test = Loader({'index': 128, 'uuid': '98ef90ab921c40e2b7504ec1ccddd0bc'})

print(f'index {test.index}')
print(f'uuid {test.uuid}')
print({name:test[name] for name in test.dtype.names})

Terminal:

<class 'int'> 128
<class 'str'> 98ef90ab921c40e2b7504ec1ccddd0bc
index 128
uuid 
{'index': array(128), 'uuid': array('', dtype='<U0')}

The returned recarray should have 'uuid' available the same as 'index' but it returns empty. No error because 'uuid' is indeed in this recarray but with an empty value.

Freelax FPV
  • 5
  • 1
  • 2

0 Answers0