Skip to content

BUG: flatten method does not validate its argument. #6598

Closed

Description

@WarrenWeckesser

According to the docstring of the flatten method, the argument should be one of 'C', 'F' or 'A'. I would expect a ValueError to be raised if the argument is not one of those values. However, it appears to ignore invalid arguments.

For example,

In [1]: import numpy as np

In [2]: np.__version__
Out[2]: '1.11.0.dev0+78d9628'

In [3]: x = np.zeros((3, 5))

In [4]: x.flatten(np.pi)  # Give flatten() a nonsense argument, and it doesn't complain.
Out[4]: 
array([ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
        0.,  0.])

I noticed this while editing the "NumPy for Matlab Users" guide, where y = x.flatten(1) was suggested as the NumPy version of the Matlab code y = x(:). (The guide has been fixed.)

Activity

  1. gfyoung commented on Dec 11, 2015

    @gfyoung
    Contributor

    From what I can tell, I believe the bug traces to code in the PyArray_OrderConverter method in this file here. I'll have a PR up for that soon!

  2. WarrenWeckesser commented on Dec 18, 2015

    @WarrenWeckesser
    MemberAuthor

    @gfyoung Thanks for fixing this.

  3. gfyoung commented on Dec 18, 2015

    @gfyoung
    Contributor

    @WarrenWeckesser : Sure thing! Your issue actually had ramifications for several other functions whose underlying functionality was tied to that order parameter. So it was good that you caught this.

  4. added a commit that references this issue on Mar 22, 2016
    0505705
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