GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — NdArray inconsistently coerces floats and ints · Issue #1914 · docarray/docarray

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

NdArray inconsistently coerces floats and ints #1914

Copy link
Copy link
Open
Open
NdArray inconsistently coerces floats and ints#1914
Copy link

Description

@nathanjmcdougall
nathanjmcdougall
opened on Dec 4, 2024
Issue body actions

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

  • Vector Database / Index
  • Representing
  • Sending
  • storing
  • multi modal data type

Activity

  1. nathanjmcdougall
    changed the title [-]NdArray inconsistently coerces floats and int[/-] [+]NdArray inconsistently coerces floats and inst[/+] on Dec 4, 2024
  2. nathanjmcdougall
    changed the title [-]NdArray inconsistently coerces floats and inst[/-] [+]NdArray inconsistently coerces floats and ints[/+] on Dec 4, 2024
  3. JoanFM commented on Dec 6, 2024

    @JoanFM
    JoanFM
    on Dec 6, 2024
    Member
    More actions

    Hey @nathanjmcdougall ,

    Thanks for reporting the issue. We will look into it. Any chance you would be able to contribute the feature?

  4. nathanjmcdougall commented on Dec 6, 2024

    @nathanjmcdougall
    nathanjmcdougall
    on Dec 6, 2024
    Author
    More actions

    I've not contributed to DocArray before - I'll take a look at the codebase this coming week sometime to see whether this is something within my capacity.

  5. 23Tarandeep57 commented on Nov 24, 2025

    @23Tarandeep57
    23Tarandeep57
    on Nov 24, 2025
    More actions

    The code was using np.ndarray(value) which treats integers as shape specifications, not values. changed the code to Check for scalar types first and use np.array([value]) to explicitly wrap them in 1D arrays.

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

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.