Skip to content

Attr 's fill attribute doesn't behave as expected. #2241

@acecchini

Description

@acecchini

Hi,

I have encountered multiple bugs related to Attr's fill attribute. Here is a minimal code repro.

import tiledb as tdb
import numpy as np

print(f"attr1: {tdb.Attr("attr1", np.dtype('c8, c8'), 1 ).fill!r}") # wrong: no structured dtype
print(f"attr2: {tdb.Attr("attr2", np.dtype('c8, c8'), 1 + 2j ).fill!r}") # wrong: no structured dtype
print(f"attr3: {tdb.Attr("attr3", np.dtype('f4, f4'), 1).fill!r}") # wrong: dtype is complex
print(f"attr4: {tdb.Attr("attr4", np.dtype('f4, f4'), 1+2j).fill!r}") # wrong: dtype is complex
print(f"attr5: {tdb.Attr("attr5", np.dtype('f4, f4'), (1, 2)).fill!r}") # wrong: dtype is complex
try:
  print(f"attr6: {tdb.Attr("attr6", np.dtype('f4, f4, f4'), 1 + 2j).fill!r}")
except TypeError as e:
  print("attr6: This TypeError is expected!") # as expected
print(f"attr7: {tdb.Attr("attr7", np.dtype('f4, f4, f4'), 1).fill!r}") # as expected
print(f"attr8: {tdb.Attr("attr8", np.dtype('f4, f4, f4'), (1, 2, 3)).fill!r}") # as expected
print(f"attr9: {tdb.Attr("attr9", np.dtype('c8, c8, c8'), 1).fill!r}") # wrong: dtype is np.dtype('f4, f4, f4')
try: 
  print(f"attr10: {tdb.Attr("attr10", np.dtype('c8, c8, c8'), 1 + 2j).fill!r}")
except TypeError as e:
  print("attr11: This TypeError is not expected. Errror message:", e)
print(f"attr11: {tdb.Attr("attr11", np.dtype('c8, c8, c8'), (1, 2, 3)).fill!r}") # wrong: dtype is np.dtype('f4, f4, f4')
try:
  print(f"attr12: {tdb.Attr("attr12", np.dtype('c8, c8, c8'), (1 + 2j, 2 + 3j, 3 + 4j)).fill!r}")
except TypeError as e: 
  print(f"attr12: This TypeError is not expected. Errror message:", e)

I get

attr1: array([1.+0.j], dtype=complex64)
attr2: array([1.+2.j], dtype=complex64)
attr3: array([1.+0.j], dtype=complex64)
attr4: array([1.+2.j], dtype=complex64)
attr5: array([1.+2.j], dtype=complex64)
attr6: This TypeError is expected!
attr7: array([(1., 1., 1.)], dtype=[('f0', '<f4'), ('f1', '<f4'), ('f2', '<f4')])
attr8: array([(1., 2., 3.)], dtype=[('f0', '<f4'), ('f1', '<f4'), ('f2', '<f4')])
attr9: array([(1., 1., 1.)], dtype=[('f0', '<f4'), ('f1', '<f4'), ('f2', '<f4')])
attr11: This TypeError is not expected. Errror message: float() argument must be a string or a real number, not 'complex'
attr11: array([(1., 2., 3.)], dtype=[('f0', '<f4'), ('f1', '<f4'), ('f2', '<f4')])
attr12: This TypeError is not expected. Errror message: float() argument must be a string or a real number, not 'complex'

while I expected:

attr1: array([(1.+0.j, 1.+0.j)], dtype=[('f0', '<c8'), ('f1', '<c8')])
attr2: array([(1.+2.j, 1.+2.j)], dtype=[('f0', '<c8'), ('f1', '<c8')])
attr3: array([(1., 1.)], dtype=[('f0', '<f4'), ('f1', '<f4'), ('f2', '<f4')])
attr4: TypeError!
attr5: array([(1, 2.)], dtype=[('f0', '<f4'), ('f1', '<f4'), ('f2', '<f4')])
attr6: This TypeError is expected!
attr7: array([(1., 1., 1.)], dtype=[('f0', '<f4'), ('f1', '<f4'), ('f2', '<f4')])
attr8: array([(1., 2., 3.)], dtype=[('f0', '<f4'), ('f1', '<f4'), ('f2', '<f4')])
attr9: array([(1.+0.j, 1.+0.j, 1.+0.j)], , dtype=[('f0', '<c8'), ('f1', '<c8'), ('f2', '<c8')])
attr10: array([(1.+2.j, 1.+2.j, 1.+2.j)], , dtype=[('f0', '<c8'), ('f1', '<c8'), ('f2', '<c8')])
attr11: array([(1.+0.j, 2.+0.j, 3.+0.j)], , dtype=[('f0', '<c8'), ('f1', '<c8'), ('f2', '<c8')])
attr12: array([(1.+2.j, 2.+3.j, 3.+4.j)], , dtype=[('f0', '<c8'), ('f1', '<c8'), ('f2', '<c8')])

Thanks :)

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