ramonhagenaars / nptyping

💡 Type hints for Numpy and Pandas
MIT License
588 stars 29 forks source link

default message for assert_isinstance #66

Closed Jasha10 closed 2 years ago

Jasha10 commented 2 years ago

This PR implements a default message for assert_isinstance.

Consider the following example:

# tmp.py
from typing import Any

import numpy as np
from nptyping import NDArray, assert_isinstance

my_arr = np.array([1, 2, 3], dtype=np.float32)
assert_isinstance(my_arr, NDArray[Any, np.int64])

Before the PR:

$ python tmp.py
Traceback (most recent call last):
...
AssertionError

The above offers little info as to what caused the failure.

After the PR:

$ python tmp.py
Traceback (most recent call last):
...
AssertionError: instance=array([1., 2., 3.], dtype=float32), cls=NDArray[Any, Int]

This should be enough to diagnose why the assertion failed.

sonarcloud[bot] commented 2 years ago

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication