Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Incorrect uses of is_numlike #7795

Closed
Milestone
@anntzer

Description

@anntzer

cbook.is_numlike(obj) is implemented by checking whetherobj + 1 raises. In particular, this means that numpy numeric arrays are considered as numlikes, which appears to be unintended in most cases.

As an example (not the only one), while

plt.scatter([0], [0], marker=[[0, 0], [0, 1], [1, 1]])

works as expected,

plt.scatter([0], [0], marker=np.array([[0, 0], [0, 1], [1, 1]]))

raises an exception because code inmarkers checks (effectively, in this case) for whethermarkers is "numlike", and, if so, considers it to be a number of sides for a polygon marker (at the beginning of_set_tuple_marker).

In my never-ending push to get rid of as much ofcbook as possible :-), I would suggest replacing calls tois_numlike to eithernp.issubdtype(type(obj), np.number) (if we were using numpy>=1.9.0, this could beisinstance(obj, abc.Number)) or, if it was actually intended to accept arrays,np.issubtype(np.asarray(obj).dtype, np.number) -- we may as well distinguish explicitly between the two cases.

Edit: Actually one can just define somewhereNumber = (abc.Number, np.number), thenisinstance(obj, Number) will work even for older numpys (I guess).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp