Skip to content

Don't return array-types for 1x1 statistics? #2308

Closed

Description

@gtsambos

By default, these statistics are returned as arrays with dimension ()

 >>> div = ts.diversity()
>>> div.shape
()

This is annoying because you have to do something like div[()] to access the value (not div[0], which is a tiny bit more intuitive at least). I think it would be better to just return the scalar value itself in this situation.

Activity

  1. changed the title [-]Don't return array-types for 1x1 statistics[/-] [+]Don't return array-types for 1x1 statistics?[/+] on May 29, 2022
  2. petrelharp commented on May 29, 2022

    @petrelharp
    Contributor

    Hah, I was just having to look up how to un-array-ify this exact thing (since you can't json.dump( ) a numpy array and things like list(ts.diversity()) doesn't work for 0-d array). I won't be surprised if there's some good reason not to change this behavior, but if changing np.array(1.5) to 1.5 won't cause problems then I'm for it.

  3. jeromekelleher commented on May 30, 2022

    @jeromekelleher
    Member

    Looking into the documentation for numpy scalars there's no obvious reason to me why we couldn't do this.

    I guess a first pass would be to try it out and see how much of our test suite it breaks?

  4. added
    enhancement
    Python API
    on May 30, 2022
  5. gtsambos commented on May 31, 2022

    @gtsambos
    MemberAuthor

    Cool! Happy to do this, but it will have to wait until after June.

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

    Python APIenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions