Skip to content

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
    • Help
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
W
wendelin.core
  • Project
    • Project
    • Details
    • Activity
    • Releases
    • Cycle Analytics
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Charts
  • Issues 1
    • Issues 1
    • List
    • Board
    • Labels
    • Milestones
  • Merge Requests 1
    • Merge Requests 1
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
    • Charts
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • nexedi
  • wendelin.core
  • Issues
  • #9

Closed
Open
Opened Nov 03, 2022 by Levin Zimmermann@levin.zimmermann
  • Report abuse
  • New issue
Report abuse New issue

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

Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
0
Labels
None
Assign labels
  • View project labels
Reference: nexedi/wendelin.core#9
GitLab Nexedi Edition | About GitLab | About Nexedi | 沪ICP备2021021310号-2 | 沪ICP备2021021310号-7