This new bugfix release of unyt
fixes bugs discovered since the v3.0.2 release.
- Fix defects when running test suite in isolation from the project's pytest configuration (PR #495). Thank you to Clément Robert (@neutrinoceros on GitHub) for the contribution.
- Drop test case for unpickling old pickle files as too sensitive to upstream changes (PR #498). Thank you to Clément Robert (@neutrinoceros on GitHub) for the contribution.
- Fix signature incompatibilities in nep 18 wrapped functions (PR #500). Thank you to Clément Robert (@neutrinoceros on GitHub) for the contribution.
- Fix an incompatibility with sympy 1.13.0rc1 (PR #504). Thank you to Clément Robert (@neutrinoceros on GitHub) for the contribution.
- Adjust doctests to changes in array repr from numpy 2.0 (PR #506). Thank you to Clément Robert (@neutrinoceros on GitHub) for the contribution.
- TST: declare np.unstack as subclass-safe (fix incompatibility with Numpy 2.1) (PR #509). Thank you to Clément Robert (@neutrinoceros on GitHub) for the contribution.
This new bugfix release of unyt
fixes bugs discovered since the v3.0.1 release,
and is intended to be compatible with the upcoming NumPy 2.0 release.
- Fix minimal requirement on setuptools_scm (PR #471). Thank you to Clément Robert (@neutrinoceros on GitHub) for the contribution.
- Explicitly forbid destructive edits to the default unit registry (PR #475). Thank you to Clément Robert (@neutrinoceros on GitHub) for the contribution.
- Fix an issue where array functions would raise
UnitInconsistencyError
when operands' units differ by some dimensionless factor (PR #478). Thank you to Clément Robert (@neutrinoceros on GitHub) for the contribution. - Implement and test array functions new in numpy 2.0 (PR #483). Thank you to Clément Robert (@neutrinoceros on GitHub) for the contribution.
- Fix compat with numpy dev for
np.trapezoid
(previously named np.trapz) (PR #486). Thank you to Clément Robert (@neutrinoceros on GitHub) for the contribution. - Implement missing support for
np.cbrt
(PR #491). Thank you to @yuyttenhove for the contribution. - Fix compatibility with numpy 2.0 copy semantics (PR #492). Thank you to Clément Robert (@neutrinoceros on GitHub) for the contribution.
This new bugfix release of unyt
fixes a few bugs since the v3.0.0 release.
- Fix an issue where array functions would raise
UnitConsistencyError
onunyt_array
objects using non-default unit registries (PR #463). Thank you to Clément Robert (@neutrinoceros on GitHub) for the contribution. - Fix an issue where array functions would crash (
AttributeError
) when passed non-ndarray
array-like objects (e.g. Python lists) (PR #464). Thank you to Clément Robert (@neutrinoceros on GitHub) for the contribution. - Fix backward compatibility for calling
numpy.histogram
with implicit range units (PR #466). Thank you to Clément Robert (@neutrinoceros on GitHub) for the contribution.
This new major release of unyt
fixes a number of issues and adds a number
of new features. Major contributions include:
- Support for Python 3.8 has been dropped.
- Support for Python 3.12 has been added.
- Support for NumPy <1.19.3 has been dropped.
- Support for SymPy <1.7 has been dropped.
- A new
unyt_dask_array
class, which implements a subclass of standard dask arrays with units attached, has been added (PR #185). See :ref:`dask` for more details. Thank you to Chris Havlin (@chrishavlin on Github) for the contribution. - A number of new metric and non-metric units have been added in PR #441. Thank you to John ZuHone (@jzuhone on GitHub) for the contribution.
- A number of common values for the solar metallicity found in the literature have been added as new metallicity units (PR #315). See :ref:`metal_conversions` for more details. Thank you to John ZuHone (@jzuhone on GitHub) for the contribution.
- The "liter" unit has been added (PR #305). Thank you to Nathan Goldbaum (@ngoldbaum on GitHub) for the contribution.
- The following common systems engineering units for energy have been added:
MMBTU
,therm
,quad
, andWh
(PR #294). Thank you to Sam Dotson (@samgdotson on GitHub) for the contribution. - The
@returns
decorator (documented in :ref:`checking_units`) now allows dimension-checking of multiple return values (PR #435). Thank you to Daniel Bates (@db434 on GitHub) for the contribution. - A number of PRs to support NEP 18, including the following (thank you to Clément Robert, @neutrinoceros on GitHub, and Nathan Goldbaum, @ngoldbaum on Github, for the contributions):
- A fix for for the LaTeX representation of Planck units (PR #379). Thank you to Peter Hayman (@haymanpf on GitHub) for the contribution.
- A fix for a bug that prevented the conversion of dimensionless arrays to their corresponding AstroPy Quantities (PR #437). Thank you to Clément Robert (@neutrinoceros on GitHub) for the contribution.
- A fix for a bug in subtraction of temperature quantities that resulted in
degC
units being returned instead ofdelta_degC
units (PR #413). Thank you to Clément Robert (@neutrinoceros on GitHub) for the contribution. - Fixes for issues with the comparison of temperature quantities (PR #408 and PR #412). Thank you to Clément Robert (@neutrinoceros on GitHub) for the contribution.
- Support for versions of NumPy < 1.19 has been dropped in this version (PR #403). Thank you to Clément Robert (@neutrinoceros on GitHub) for the contribution.
- A number of PRs to support NumPy 2.0, thank you to Clément Robert (@neutrinoceros on GitHub) for the contributions:
- Fix a regression where arrays elements with dtype
'int8'
would not compare to floats as intended. See PR #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 and PR #376. Thank you to Nathan Goldbaum (@ngoldbaum on GitHub) for the contribution.
Make
unyt_quantity.from_string
parse ints. See PR #278. Thank you to Nathan Goldbaum (@ngoldbaum on GitHub) for the contribution.TST: migrate from tox-pyenv to tox-gh-actions #344 See PR #344. Thank you to Clément Robert (@neutrinoceros on GitHub) for the contribution.
Correctly test string comparison depending on numpy version #358 See PR #358. Thank you to Clément Robert (@neutrinoceros on GitHub) for the contribution.
Multiple fixes for
unyt_quantity.from_string
- fix a bug where
unyt_quantity.from_string
would drop part of the unit expression - fix a bug where
unyt_quantity.from_string
would choke on unit expressions starting with'*'
or'/'
- fix a bug where
unyt_quantity.from_string
would choke on space-separated unit expressions - fix roundtrip for
unyt_quantity.from_string
andunyt_quantity.to_string
methods - simplify unit regexp (
'**/2'
isn't a valid exponent) - fix a bug where malformed string input would be incorrectly parsed by
unyt_quantity.from_string
See PR #362. Thank you to Clément Robert (@neutrinoceros on GitHub) for the contribution, and to Chris Byrohl (@cbyrohl on GitHub) for the report.
- fix a bug where
- Fix a future incompatibility with numpy 1.25 (unreleased) where comparing
unyt_array
objects to non-numeric objects (e.g. strings) would cause a crash. See PR #333. Thank you to Clément Robert (@neutrinoceros on GitHub) and Nathan Goldbaum (@ngoldbaum on GitHub) for the contribution.
- Fix an issue where taking powers of units was backwards-incompatible with previous
versions of
unyt
when the exponent is not zero. See PR #249. Thank you to Clément Robert (@neutrinoceros on GitHub) for the contribution. - The import time for
unyt
has been reduced by skipping version checking of other packages. See PR #251. Thank you to Clément Robert (@neutrinoceros on GitHub) for the contribution.
- Dropped support for Python 3.6 and 3.7.
- Added support for Python 3.8, 3.9 and 3.10.
- Fix an issue where SI prefixes of the
degC
units would give incorrect values in conversions. See PR #176. Thank you to Lee Johnston (@l-johnston on GitHub) for the contribution. - Fix an issue when using
matplotlib_support
, plot an empty unyt array, would result in an error when changing units. See PR #180. Thank you to Josh Borrow (@JBorrow on GitHub) for the contribution. - Fix an issue where units would be printed twice in formatted strings with
an
unyt_array
embedded. See PR #188. Thank you to Clément Robert (@neutrinoceros on GitHub) for the contribution. - Add a method to parse a
unyt_quantity
from a string expression. See PR #191. Thank you to Clément Robert (@neutrinoceros on GitHub) for the contribution. - Fix an issue where a
unyt_array
with dtype int8 could not be converted to a different unit. See PR #197. Thank you to Clément Robert (@neutrinoceros on GitHub) for the contribution. - The import time for
unyt
has been reduced. See PR #199. Thank you to Clément Robert (@neutrinoceros on GitHub) for the contribution. - Fix an issue where taking an
unyt_array
orunyt_quantity
to a zero power would retain the units of the original array or quantity instead of converting to a dimensionless array. See PR #204. Thank you to Josh Borrow (@JBorrow on GitHub) for the contribution. - Add support for coercing iterables of
unyt_array
objects with nonuniform dimensionally equivalent units to a singleunyt_array
. See PR #211. Thank you to Nathan Goldbaum (@ngoldbaum on GitHub) for the contribution. - Add the civil engineering units
pli
,plf
,psf
,kli
,klf
, andksf
. See PR #217. Thank you to @osnippet on GitHub for the contribution. - Fix typos in constants and unit prefixes. See PR #218. Thank you to Clément Robert (@neutrinoceros on GitHub) for the contribution.
- Fix an issue where multiplying a 1-element
unyt_array
would return aunyt_quantity
. See PR #225. Thank you to Clément Robert (@neutrinoceros on GitHub) for the contribution. - Add the Rydberg constant
R_∞
and unitRy
, add the dimensionangular_frequency
and the unitrpm
, and increase the precision of Avogadro's number. See PR #228. - Fix an issue where
np.divide.reduce
would return incorrect units forunyt_array
instances. See PR #230. Thank you to Kyle Oman (@kyleaoman on GitHub) for the contribution.
- Dropped support for Python 3.5.
- Add
delta_degC
anddelta_degF
units to support temperature difference arithmetic. See PR #152. Thank you to Lee Johnston (@l-johnston on GitHub) for the contribution. - Fix an issue where a subsequent load of the unit registry with units that are equal but not identical leads to a crash. See PR #158. Thank you to Matthew Turk (@matthewturk on GitHub) for the initial bug report and fix.
- Add force unit
kip
and pressure unitpsi
. Thank you to P. Talley (@otaithleigh on GitHub) for the contribution. See PR #162. - Fix an issue where arithmetic operations on units defined in different registries and having the conversion defined in one direction would lead to a crash. See PR #164. Thank you to Clément Robert (@neutrinoceros on GitHub) for the initial bug report and fix.
- The
unyt.returns
andunyt.accepts
decorators now work correctly for functions that accept or return data with dimensionless units. See PR #146. Thank you to Simon Schopferer (@simfinite on GitHub) for the initial bug report and fix. - Data used in the tests are packaged with the source distribution and
unyt.test()
is now itself run as part of unyt's continuous integration tests. See PR #149 and PR #150. Thank you to Miguel de Val-Borro (@migueldvb on GitHub) for the initial bug report and fix. - The
degC
anddegF
units now render as°C
and°F
by default,°C
and°F
are now recognized as valid unit names as well. Thank you to Lee Johnston (@l-johnston on GitHub) for the contribution. - Use a more canonical representation of the micro symbol when printing units with the micro prefix, avoiding issues with displaying unit names in Matplotlib plot labels. See PR #153. Thank you to Matthew Turk (@matthewturk on GitHub) for the bug report and fix.
- Add more alternative spellings for solar units. See PR #155. Thank you to Clément Robert (@neutrinoceros on GitHub) for the initial bug report.
- Fix compatibility with
unyt_array
subclasses that do not have the newname
argument in their initializer. See PR #140. - Fix an issue where custom units added to a unit registry were not restored correctly when reloading a unit registry from a JSON or pickle representation. See PR #140.
- The
unyt_array
andunyt_quantity
classes now have a new, optionalname
attribute. The primary purpose of this attribute is to enable automatic generation of matplotlib plot labels. Thename
attribute is propagated through unit conversions and copies but is not propagated through mathematical operations. See PR #129 and the documentation for details. - Add support for the
Neper
andBel
units with logarithmic dimensions. This includes support for thedecibel
unit. Note that logarithmic units can only be used with other logarithmic units and must be applied and stripped manually. See PR #133 and PR #134. - Add support for the SI unit of inductance,
H
. See PR #135. - Fix formatting of error message produced when raising a quantity to a power with units. See PR #131. Thank you to Lee Johnston (@l-johnston on GitHub) for all of the above contributions.
- Fix incorrect unit metadata when loading a pickled array saved by
yt.units
. See PR #137.
- Matplotlib support is no longer enabled by importing
unyt
. Instead, it is now necessary to use theunyt.matplotlib_support
context manager in code where you want unyt to automatically generate plot labels. Enabling Matplotlib support by default in the previous release caused crashes in previously working code for some users so we have decided to make the plotting support optional. See the documentation for more details. We are sorry for introducing a new feature that broke some user's code. See PR #126. Thank you to Lee Johnston (@l-johnston on GitHub) for the contribution. - Updated the contribution guide to include more details about setting up
multiple Python versions for the
tox
tests.
- Importing unyt now registers unyt with Matplotlib's interface for handling units. See the Matplotlib and unyt documentation for more details. See PR #122 and PR #124. Thank you to Lee Johnston (@l-johnston on GitHub) for the contribution.
- Updated the LaTeX formatting of solar units so they do not get rendered italicized. See PR #120. Thank you to Josh Borrow (@JBorrow on GitHub) for the contribution.
- Reduce floating point round-off error when data are converted from integer to float dtypes. See PR #119.
- Add support for the latest releases of h5py, sympy, NumPy, and PyTest. See PR #115.
- Fix the hash implementation so that identical units cannot have distinct hashes. See PR #114 and PR #117. Thank you to Ben Kimock (@saethlin on GitHub) for the contribution.
- Improve performance for creating quantities or small arrays via multiplication
with a unit object. Creating an array or quantity from data that does not have
a numeric dtype will now raise
UnitOperationError
instead ofUnitDtypeError
, which has been removed. See PR #111. - Comparing data with units that have different dimensions using the
==
and!=
operators will no longer raise an error. Other comparison operators will continue to raise errors. See PR #109. - Fixed a corner case in the implementation of
clip
. See PR #108. Thank you to Matthew Turk (@matthewturk on GitHub) for the contribution. - Added
%
as a valid dimensionless unit with a value of0.01
, also available under the namepercent
. See PR #106. Thank you to Thomas Hisch for the contribution. - Added
bar
to the default unit lookup table. See PR #103. Thank you to Thomas Hisch (@thisch on GitHub) for the contribution.
- Added support for the
clip
ufunc added in NumPy 1.17. See PR #102.
- Added
unyt.dimensions.accepts
andunyt.dimensions.returns
, decorators that can be used to ensure that data passed into a decorated function has units that are dimensionally consistent with the function's expected inputs. See PR #98. Thank you to Andrei Berceanu (@berceanu on GitHub) for the contribution. - Added
unyt.allclose_units
and improved documentation for writing tests for code that usesunyt
. This is a wrapper fornumpy.allclose
that also checks the units of the input arrays. See PR #94. Thank you to Andrei Berceanu (@berceanu on GitHub) for the contribution.
- Fix erroneous conversions of E&M units to their "native" unit system, for example, converting Gauss to CGS units would return Tesla and converting Tesla to MKS units would return Gauss. See PR #96.
- Add support for loading JSON unit registries saved by
yt.units
. See PR #93. - Correct the value of the
light_year
unit. See PR #93. - It is now possible to define a
UnitSystem
object with a quantity. See PR #86. - Incorrect units for Planck units have been fixed. See PR #85. Thank you to Nathan Musoke (@musoke on GitHub) for the contribution.
- Updated value of Newton's constant to latest CODATA value. See PR #84.
- Several performance optimizations. This includes a slight change to the behavior of MKS/CGS E&M unit conversions that makes the conversion rules slightly more relaxed. See PR #82.
- Fixed an issue with restoring unit registries from JSON output. See PR #81.
This release includes a few minor new features and bugfixes for the 2.0.0 release.
- Added support for the matmul
@
operator. See PR #80. - Allow defining unit systems using
Unit
instances instead of string unit names. See PR #71. Thank you to Josh Borrow (@JBorrow on GitHub) for the contribution. - Fix incorrect behavior when
uhstack
is called with theaxis
argument. See PR #73. - Add
"rsun"
,"lsun"
, and"au"
as alternate spellings for the"Rsun"
,"Lsun"
, and"AU"
units. See PR #77. - Improvements for working with code unit systems. See PR #78.
- Reduce impact of floating point round-off noise on unit comparisons. See PR #79.
unyt
2.0.0 includes a number of exciting new features as well as some
bugfixes. There are some small backwards incompatible changes in this release
related to automatic unit simplification and handling of dtypes. Please see the
release notes below for more details. If you are upgrading from unyt 1.x
we
suggest testing to make sure these changes do not significantly impact you. If
you run into issues please let us know by opening an issue on GitHub.
Dropped support for Python 2.7 and Python 3.4. Added support for Python 3.7.
Added
Unit.simplify()
, which cancels pairs of terms in a unit expression that have inverse dimensions and made it so the results ofunyt_array
multiplication and division will automatically simplify units. This means operations that combine distinct dimensionally equivalent units will cancel in many situations. For example>>> from unyt import kg, g >>> print((12 * kg) / (4 * g)) 3000.0 dimensionless
older versions of
unyt
would have returned4.0 kg/g
. See PR #58 for more details. This change may cause the units of operations to have different, equivalent simplified units than they did with older versions ofunyt
.Added the ability to resolve non-canonical unit names to the equivalent canonical unit names. This means it is now possible to refer to a unit name using an alternative non-canonical unit name when importing the unit from the
unyt
namespace as well as when a unit name is passed as a string tounyt
. For example:>>> from unyt import meter, second >>> data = 1000.0 * meter / second >>> data.to("kilometer/second") unyt_quantity(1., 'km/s') >>> data.to("metre/s") unyt_quantity(1000., 'm/s')
The documentation now has a table of units recognized by
unyt
along with known alternative spellings for each unit.Added support for unicode unit names, including
μm
for micrometer andΩ
for ohm. See PR #59.Substantially improved support for data that does not have a
float64
dtype. Rather than coercing all data tofloat64
unyt
will now preserve the dtype of data. Data that is not already a numpy array will be coerced to a dtype by callingnp.array
internally. Converting integer data to a new unit will convert the data to floats, if this causes a loss of precision then a warning message will be printed. See PR #55 for details. This change may cause data to be loaded intounyt
with a different dtype. On Windows the default integer dtype isint32
, so data may begin to be recognized asint32
or converted tofloat32
where before it was interpreted asfloat64
by default.Unit registries are now associated with a unit system. This means that it's possible to create a unit registry that is associated with a non-MKS unit system so that conversions to "base" units will end up in that non-MKS system. For example:
>>> from unyt import UnitRegistry, unyt_quantity >>> ureg = UnitRegistry(unit_system="cgs") >>> data = unyt_quantity(12, "N", registry=ureg) >>> data.in_base() unyt_quantity(1200000., 'dyn')
See PR #62 for details.
Added two new utility functions,
unyt.unit_systems.add_constants
andunyt.unit_systems.add_symbols
that can populate a namespace with a set of unit symbols in the same way that the top-levelunyt
namespace is populated. For example, the author of a library making use ofunyt
could create an object that users can use to access unit data like this:>>> from unyt.unit_systems import add_symbols >>> from unyt.unit_registry import UnitRegistry >>> class UnitContainer: ... def __init__(self): ... add_symbols(vars(self), registry=UnitRegistry()) ... >>> units = UnitContainer() >>> units.kilometer km >>> units.microsecond μs
See PR #68.
The
unyt
codebase is now automatically formatted by black. See PR #57.Add missing "microsecond" name from top-level
unyt
namespace. See PR #48.Add support for
numpy.argsort
by definingunyt_array.argsort
. See PR #52.Add Farad unit and fix issues with conversions between MKS and CGS electromagnetic units. See PR #54.
Fixed incorrect conversions between inverse velocities and
statohm
. See PR #61.Fixed issues with installing
unyt
from source with newer versions ofpip
. See PR #63.Fixed bug when using
define_unit
that caused crashes when using a custom unit registry. Thank you to Bili Dong (@qobilidob on GitHub) for the pull request. See PR #64.
We would also like to thank Daniel Gomez (@dangom), Britton Smith (@brittonsmith), Lee Johnston (@l-johnston), Meagan Lang (@langmm), Eric Chen (@ericchen), Justin Gilmer (@justinGilmer), and Andy Perez (@sharkweek) for reporting issues.
Trigger zenodo archiving.
Minor paper updates to finalize JOSS submission.
unyt
1.0.5 includes changes that reflect the peew review process for the
JOSS method paper. The peer reviewers were Stuart Mumfork (@cadair), Trevor Bekolay (@tbekolay), and Yan Grange (@ygrange). The editor was Kyle Niemeyer (@kyleniemeyer). The unyt
development team thank our
reviewers and editor for their help getting the unyt
paper out the door as
well as for the numerous comments and suggestions that improved the paper and
package as a whole.
In addition we'd like to thank Mike Zingale, Meagan Lang, Maksin Ratkin, DougAJ4, Ma Jianjun, Paul Ivanov, and Stephan Hoyer for reporting issues.
- Added docstrings for the custom exception classes defined by
unyt
. See PR #44. - Added improved documentation to the contributor guide on how to run the tests and what the PR review guidelines are. See PR #43.
- Updates to the text of the method paper in response to reviewer suggestions. See PR #42.
- It is now possible to run the tests on an installed copy of
unyt
by executingunyt.test()
. See PR #41. - Minor edit to LICENSE file so GitHub recognizes it. See PR #40. Thank you to Kyle Sunden (@ksunden) for the contribution.
- Add spatial frequency as a dimension and added support in the
spectral
equivalence for the spatial frequency dimension. See PR #38 Thank you to Kyle Sunden (@ksunden) for the contribution. - Add support for Python 3.7. See PR #37.
- Importing
unyt
will now fail ifnumpy
andsympy
are not installed. See PR #35 - Testing whether a unit name is contained in a unit registry using the Python
in
keyword will now work correctly for all unit names. See PR #31. - The aliases for megagram in the top-level unyt namespace were incorrectly set to reference kilogram and now have the correct value. See PR #29.
- Make it possible to take scalars to dimensionless array powers with a properly broadcasted result without raising an error about units. See PR #23.
- Whether or not a unit is allowed to be SI-prefixable (for example, meter is
SI-prefixable to form centimeter, kilometer, and many other units) is now
stored as metadata in the unit registry rather than as global state inside
unyt
. See PR #21. - Made adjustments to the rules for converting between CGS and MKS E&M units so that errors are only raised when going between unit systems and not merely when doing a complicated unit conversion involving E&M units. See PR #20.
round(q)
whereq
is aunyt_quantity
instance will no longer raise an error and will now return the nearest rounded float. See PR #19.- Fixed a typo in the readme. Thank you to Paul Ivanov (@ivanov) for the fix.
- Added smoot as a unit. See PR #14.
- Expand installation instructions
- Mention paper and arxiv submission in the readme.
- Fix readme rendering on pypi
- Added a paper to be submitted to the Journal of Open Source Software.
- Tweaks for the readme
- Don't use setup_requires in setup.py
- First release on PyPI.
- unyt began life as a submodule of yt named yt.units.
- It was separated from yt.units as its own package in 2018.