Hi all,

This was probably announced before, but I wanted to mention it again,
with https://github.com/numpy/numpy/pull/19226 as the last step the
casting safety, promotion, and comparisons of structured (void) dtypes
will be updated to fix some bugs and fit better with changes that
happened a few years ago already.

The most interesting change is probably to comparisons:  It is now
possible to compare sturctured dtypes when included dtypes mismatch:

    arr1 = np.array([1, 2, 3], dtype="i,i")
    arr2 = np.array([1, 2, 1], dtype="i,f8")  # note the f8
    arr1 == arr2
    # Will now return [True, True, False]

while previously this returned `False` with a `FutureWarning` (although
that warning was not quite correct.  Comparisons will now always
generally succeed if the two dtypes can be promoted.

The other change to `==` and `!=` is that in cases where promotion is
not possible, a `TypeError` will now be given for structured dtype
comparisons.  (Previously, also `False` with a `FutureWarning`)

These changes align with the changes in promotion for structured
dtypes.  Structured dtypes will now correctly promote all included
dtypes if the number of fields, names, and titles match exactly.
Further, structured dtypes will remove any unnecessary empty space when
promoted.  The result is considered "canonical" with the removed
padding.

In alignment with the above changes to the promotion logic, the
casting safety has been updated:

* "equiv" enforces matching names and titles. The itemsize
  is allowed to differ due to padding.
* "safe" allows mismatching field names and titles
* The cast safety is limited by the cast safety of each included
  field.
* The order of fields is used to decide cast safety of each
  individual field.  Previously, the field names were used and
  only unsafe casts were possible when names mismatched.

The main important change here is that name mismatches are now
considered "safe" casts.  The cast itself already worked using the
field order.


Cheers,

Sebastian

_______________________________________________
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: arch...@mail-archive.com

Reply via email to