FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

NdArray inconsistently coerces floats and ints · Issue #1914 · docarray/docarray · GitHub

This repository was archived by the owner on Sep 9, 2026. It is now read-only.

Repository navigation

This repository was archived by the owner on Sep 9, 2026. It is now read-only.

NdArray inconsistently coerces floats and ints #1914

Description

Initial Checks

  • I have read and followed the docs and still think this is a bug

Description

I would expect floats and ints to be consistently either able to be coerced to NdArrays or not.

Floats cannot be coerced.

Ints can be coerced - but not in the expected way. It seems to use np.empty to initialize an array with N element where N is the int being coerced.

Generally, I would expect that an int or a float would be coerced to a 1-dimensional array with a single element.

Example Code

from docarray import BaseDoc
from docarray.typing import NdArray

class MyDoc(BaseDoc):
    arr: NdArray

MyDoc(arr=10).arr # Undefined behaviour; uninitialized array
>> NdArray([7.17677097e-312, 1.77863633e-322, 0.00000000e+000,
         0.00000000e+000, 5.28555753e+180, 5.98847221e+174,
         5.92957407e-038, 7.42262642e-091, 2.80246406e-032,
                     nan])
MyDoc(arr=10.0).arr # ValidationError

I would expect instead:

MyDoc(arr=10).arr
>> NdArray([10])
MyDoc(arr=10.0).arr
>> NdArray([10.0])

Python, DocArray & OS Version

Python 3.11.9
docarray 0.40.0
Windows 10

Affected Components

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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


      Back | FazBrowse Home | New Git URL