deeplake icon indicating copy to clipboard operation
deeplake copied to clipboard

Auto-convert numbers to strings when appending to a text dtype tensor

Open nvoxland-al opened this issue 4 months ago • 2 comments

🚀 🚀 Pull Request

Impact

  • [X] Bug fix (non-breaking change which fixes expected existing functionality)
  • [ ] Enhancement/New feature (adds functionality without impacting existing logic)
  • [ ] Breaking change (fix or feature that would cause existing functionality to change)

Description

A script such as this:

print(ds.str_tensor.numpy())  # prints [['1']]
print(ds.num_tensor.numpy())  # prints [[1]]
print("-----")

ds.append(
    {"str_tensor": 2, "num_tensor": 2}
)  # no error, just first tensor is appended as empty string
print(ds.str_tensor.numpy())  # prints [['1']  ['']]
print(ds.num_tensor.numpy())  # prionts [[1] [2]]
print("-----")

ds.num_tensor.append(3)
ds.str_tensor.append(3)  # same here
print(ds.str_tensor.numpy())  # prints  [['1'] [''] ['']]
print(ds.num_tensor.numpy())  # [[1] [2] [3]]
print("-----")

silently appends the numbers in str_tensor as empty strings.

This PR makes numbers automatically convert to strings, and throw an error for all other types. This keeps something more unexpected like ds.str_tensor.append([1,2,3]) from being auto-converted to a string

nvoxland-al avatar Feb 23 '24 16:02 nvoxland-al