Skip to content

GitLab

  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • W wendelin.core
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 1
    • Issues 1
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 6
    • Merge requests 6
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • nexedi
  • wendelin.core
  • Issues
  • #9

Closed
Open
Created Nov 03, 2022 by Levin Zimmermann@levin.zimmermannMaintainer

Inconsistency in behaviour between numpy.ndarray and ZBigArray

Hello,

I encountered an unexpected behavior when using wendelin.bigarray.array_zodb.ZBigArray.

When initializing a ZBigArray by using a list for the shape parameter, the append method will raise an error:

>>> from wendelin.bigarray.array_zodb import ZBigArray
>>> zbig_array = ZBigArray(shape=[1], dtype=float)
>>> zbig_array.append([1])
ValueError: all the input array dimensions except for theconcatenation axis must match exactly

It will raise this error because it will come to [] != () here: zbig_array.shape returns a list, but the shape property of the adhoc created array which is supposed to be appended returns a tuple.

It's fair to say this is actually an users error, because the numpy documentation clearly specifies the shape parameter as a tuple of ints.

Nevertheless recent versions of numpy.ndarray still do accept a list as a valid input of shape:

>>> import numpy
>>> numpy.__version__
1.23.1
>>> numpy.ndarray(shape=[2]).shape
(2,)
>>> numpy.ndarray(shape=[2]).shape == numpy.ndarray(shape=(2,)).shape
True

What is the preferred way how to handle this difference in behavior between numpy.ndarray and wendelin.bigarray.array_zodb.ZBigArray?

I've thought about:

  1. Simply wrapping shape into a tuple call here (e.g. self._shape = tuple(shape)).

  2. Somehow improve the error message. It's perhaps not a big deal, but it can be confusing and time-consuming when encountering the described append scenario with the bad shape parameter.

Best, Levin

/cc @kirr

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking
GitLab Nexedi Edition | About GitLab | About Nexedi | 沪ICP备2021021310号-2 | 沪ICP备2021021310号-7