Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REL: prepare release 2.9.5 #372

Merged
merged 4 commits into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,26 @@
History
=======

2.9.5 (2023-02-22)
------------------

* Fix a regression where arrays elements with dtype ``'int8'`` would not compare to floats
as intended. See `PR #371 <https://github.com/yt-project/unyt/pull/371>`_. Thank you to
Clément Robert (@neutrinoceros on GitHub) and Nathan Goldbaum (@ngoldbaum on GitHub) for
the contribution.

* Raise an error in case an array element is assigned to a new value with incompatible
units. See `PR #375 <https://github.com/yt-project/unyt/pull/375>`_ and `PR #376
<https://github.com/yt-project/unyt/pull/376>`_. Thank you to Nathan Goldbaum
(@ngoldbaum on GitHub) for the contribution.


2.9.4 (2023-02-06)
------------------

* Make ``unyt_quantity.from_string`` parse ints.
See `PR #278 <https://github.com/yt-project/unyt/pull/278>`_.
Thank you to Nahan Goldbaum (@ngoldbaum on GitHub) for the contribution.
Thank you to Nathan Goldbaum (@ngoldbaum on GitHub) for the contribution.
* TST: migrate from tox-pyenv to tox-gh-actions #344
See `PR #344 <https://github.com/yt-project/unyt/pull/344>`_.
Thank you to Clément Robert (@neutrinoceros on GitHub) for the contribution.
Expand Down
15 changes: 14 additions & 1 deletion unyt/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,14 @@

NULL_UNIT = Unit()
POWER_MAPPING = {multiply: lambda x: x, divide: lambda x: 2 - x}
DISALLOWED_DTYPES = ("S", "U", "a", "O", "M", "m", "b")
DISALLOWED_DTYPES = (
"S", # bytestring
"a", # bytestring
"U", # (unicode) bytes
"O", # Python object
"M", # datetime
"m", # timedelta
)

__doctest_requires__ = {
("unyt_array.from_pint", "unyt_array.to_pint"): ["pint"],
Expand Down Expand Up @@ -1721,6 +1728,12 @@ def __getitem__(self, item):
pass
return ret

def __setitem__(self, item, value):
if hasattr(value, "units"):
if value.units != self.units and value.units != NULL_UNIT:
value = value.to(self.units)
super().__setitem__(item, value)

def __pow__(self, p, mod=None, /):
"""
Power function, over-rides the ufunc as
Expand Down
25 changes: 25 additions & 0 deletions unyt/tests/test_unyt_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -2739,3 +2739,28 @@ def test_string_comparison():
a = 1 * cm
assert not (a == "hello")
assert a != "hello"


def test_int8_comparison():
# see regression https://github.com/yt-project/unyt/issues/369
a = unyt_array(np.zeros(5, dtype=np.int8))
assert all(e == 0 for e in a)


def test_setitem():
# see https://github.com/yt-project/unyt/issues/373
a = [1, 2, 3] * cm
a[1] = 2 * m
assert a[1].value == 200
assert a[1].units == cm

with pytest.raises(UnitConversionError):
a[1] = 2 * g

a[1] = 2
assert a[1].value == 2
assert a[1].units == cm

a[1] = unyt_quantity(2)
assert a[1].value == 2
assert a[1].units == cm