Skip to content

Commit

Permalink
Fix failing tests
Browse files Browse the repository at this point in the history
Fix isnan to use unp.isnan as appropriate for both duck_array_type and objects of UFloat types.

Fix a minor typo in pint/facets/__init__.py comment.

In test_issue_1400, use decorators to ensure babel library is loaded when needed.

pyproject.toml: revert change to testbase; we fixed with decorators instead.

Signed-off-by: Michael Tiemann <[email protected]>
  • Loading branch information
MichaelTiemannOSC committed Sep 15, 2023
1 parent f55b8de commit 00f08f3
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
17 changes: 12 additions & 5 deletions pint/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,21 +325,28 @@ def isnan(obj: Any, check_all: bool) -> Union[bool, Iterable[bool]]:
Always return False for non-numeric types.
"""
if is_duck_array_type(type(obj)):
if obj.dtype.kind in "if":
if obj.dtype.kind in "ifc":
out = np.isnan(obj)
elif obj.dtype.kind in "Mm":
out = np.isnat(obj)
else:
# Not a numeric or datetime type
out = np.full(obj.shape, False)
if HAS_UNCERTAINTIES:
try:
out = unp.isnan(obj)
except TypeError:
# Not a numeric or UFloat type
out = np.full(obj.shape, False)
else:
# Not a numeric or datetime type
out = np.full(obj.shape, False)
return out.any() if check_all else out
if isinstance(obj, np_datetime64):
return np.isnat(obj)
elif HAS_UNCERTAINTIES and isinstance(obj, UFloat):
return unp.isnan(obj)
try:
return math.isnan(obj)
except TypeError:
if HAS_UNCERTAINTIES:
return unp.isnan(obj)
return False


Expand Down
2 changes: 1 addition & 1 deletion pint/facets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
keeping each part small enough to be hackable.
Each facet contains one or more of the following modules:
- definitions: classes describing an specific unit related definiton.
- definitions: classes describing specific unit-related definitons.
These objects must be immutable, pickable and not reference the registry (e.g. ContextDefinition)
- objects: classes and functions that encapsulate behavior (e.g. Context)
- registry: implements a subclass of PlainRegistry or class that can be
Expand Down
1 change: 1 addition & 0 deletions pint/testsuite/test_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,7 @@ def test_issue_1300(self):
m = module_registry.Measurement(1, 0.1, "meter")
assert m.default_format == "~P"

@helpers.requires_babel()
def test_issue_1400(self, sess_registry):
q1 = 3 * sess_registry.W
q2 = 3 * sess_registry.W / sess_registry.cm
Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ testbase = [
"pytest",
"pytest-cov",
"pytest-subtests",
"pytest-benchmark",
"babel"
"pytest-benchmark"
]
test = [
"pytest",
Expand Down

0 comments on commit 00f08f3

Please sign in to comment.