Skip to content

Quantity.info should not be copied in ufuncs #14248

Closed

Description

@mhvk

Description

Currently, .info gets copied also in operations like result = q1 + q2. This is because at the end of the addition, when taking a _new_view(), result.__array_finalize__(self) is called. That does not seem reasonable -- e.g., there is no reason the result should share the name and description of one of the arguments.

Expected behavior

Instead, result.info should just be empty.

Example

import astropy.units as u
q1 = [1., 2., 3.] * u.m
q1.info.name = 'q1'
q2 = 1.*u.cm
q2.info.name = 'q2'
result = q1+q2
result.info
name = q1
dtype = float64
unit = m
class = Quantity
n_bad = 0
length = 3

This actually is a long-standing issue, see #5047. But perhaps one can tackle them one at a time...

EDIT: the problem is that this makes operations needlessly slow; see #14244 (comment)

Activity

  1. mhvk commented on Jan 5, 2023

    @mhvk
    ContributorAuthor

    fixed by #14253

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions