This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author josh.r
Recipients chovey, eric.smith, josh.r, mark.dickinson
Date 2021-09-30.23:48:58
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1633045738.91.0.445757643458.issue45333@roundup.psfhosted.org>
In-reply-to
Content
This has nothing to do with properties, it's 100% about using augmented assignment with numpy arrays and mixed types. An equivalent reproducer is:

a = np.array([1,2,3])  # Implicitly of dtype np.int64

a += 0.5  # Throws the same error, no properties involved

The problem is that += is intended to operate in-place on mutable types, numpy arrays *are* mutable types (unlike normal integers in Python), you're trying to compute a result that can't be stored in a numpy array of integers, and numpy isn't willing to silently make augmented assignment with incompatible types make a new copy with a different dtype (they *could* do this, but it would lead to surprising behavior, like += on the *same* numpy array either operating in place or creating a new array with a different dtype and replacing the original based on the type on the right-hand side).

The short form is: If your numpy computation is intended to produce a new array with a different data type, you can't use augmented assignment. And this isn't a bug in CPython in any event; it's purely about the choices (reasonable ones IMO) numpy made implementing their __iadd__ overload.
History
Date User Action Args
2021-09-30 23:48:59josh.rsetrecipients: + josh.r, mark.dickinson, eric.smith, chovey
2021-09-30 23:48:58josh.rsetmessageid: <1633045738.91.0.445757643458.issue45333@roundup.psfhosted.org>
2021-09-30 23:48:58josh.rlinkissue45333 messages
2021-09-30 23:48:58josh.rcreate