
GITHUB . COM {
}
Detected CMS Systems:
- Wordpress (2 occurrences)
Title:
Attribute error in pytest.approx for types implicitly convertible to numpy arrays ยท Issue #12114 ยท pytest-dev/pytest
Description:
a detailed description of the bug or problem you are having When using pytest.approx with custom types which are implicitly convertible to numpy arrays, the following error is observed: E AssertionError: assert <test_matrix_...x7f9169ac4...
Website Age:
17 years and 8 months (reg. 2007-10-09).
Matching Content Categories {๐}
- Automotive
- Technology & Computing
- Mobile Technology & AI
Content Management System {๐}
What CMS is github.com built with?
Github.com is based on WORDPRESS.
Traffic Estimate {๐}
What is the average monthly size of github.com audience?
๐๐ Tremendous Traffic: 10M - 20M visitors per month
Based on our best estimate, this website will receive around 10,000,019 visitors per month in the current month.
However, some sources were not loaded, we suggest to reload the page to get complete results.
check SE Ranking
check Ahrefs
check Similarweb
check Ubersuggest
check Semrush
How Does Github.com Make Money? {๐ธ}
Subscription Packages {๐ณ}
We've located a dedicated page on github.com that might include details about subscription plans or recurring payments. We identified it based on the word pricing in one of its internal links. Below, you'll find additional estimates for its monthly recurring revenues.How Much Does Github.com Make? {๐ฐ}
Subscription Packages {๐ณ}
Prices on github.com are in US Dollars ($).
They range from $4.00/month to $21.00/month.
We estimate that the site has approximately 4,989,889 paying customers.
The estimated monthly recurring revenue (MRR) is $20,957,532.
The estimated annual recurring revenues (ARR) are $251,490,385.
Wordpress Themes and Plugins {๐จ}
What WordPress theme does this site use?
It is strange but we were not able to detect any theme on the page.
What WordPress plugins does this website use?
It is strange but we were not able to detect any plugins on the page.
Keywords {๐}
numpy, def, array, implicitly, convertible, vec, poulamisau, pytestapprox, implicitarray, attribute, error, type, bug, case, vals, return, test, types, issue, class, added, sign, pytest, arrays, assert, approx, mytype, shape, commented, fixed, code, pull, projects, problem, object, initself, selfvals, reprself, fselfclassnameselfvals, arrayself, dtypenone, copynone, nparrayselfvals, contributor, testingpythonapproxpy, tox, nicoddemus, navigation, requests, actions,
Topics {โ๏ธ}
poulami-sau edits contributor 10/site-packages/_pytest/python_api 3989384 poulami-sau mentioned approx function type venv/lib/python3 pull request test case providโฆ comment metadata assignees assigned labels topic approx sensibly chooses testing/python/approx type projects projects milestone attribute error types implicitly convertible numpy implementation approxnumpy shape check assumes attribute 'shape' shape attribute test case numpy arrays import numpy error message detailed description faulty __repr__ vec1 = mytype np = pytest fixed bug code case output relevant packages implicitly convertible custom types class testapprox types implicโฆ def __init__ def __array__ def test_approx_eq test cases def test_numpy_array_implicit_conversion approx determines approx related class implicitarray vec2 = mytype vec1 = implicitarray addressed type 'mytype' object pytest_assertion plugin details failed current head
Payment Methods {๐}
- Braintree
Questions {โ}
- Already have an account?
- Do you have any pointers?
Schema {๐บ๏ธ}
DiscussionForumPosting:
context:https://schema.org
headline:Attribute error in pytest.approx for types implicitly convertible to numpy arrays
articleBody:- [x] a detailed description of the bug or problem you are having
When using pytest.approx with custom types which are implicitly convertible to numpy arrays, the following error is observed:
```
E AssertionError: assert <test_matrix_...x7f9169ac4ca0> == approx([1.0 ยฑ....0 ยฑ 4.0e-06])
E (pytest_assertion plugin: representation of details failed: ~/.venv/lib/python3.10/site-packages/_pytest/python_api.py:175: AttributeError: 'MyType' object has no attribute 'shape'.
E Probably an object has a faulty __repr__.)
```
Note: The line number in the error message is a little off from the current head. That line is [here](https://github.com/pytest-dev/pytest/blob/14437788f07584fcf0578bdb952c720e0b9dd2ab/src/_pytest/python_api.py#L166).
Looking at the code, `pytest.approx` sensibly chooses the numpy implementation `ApproxNumpy`, because the expected value is implicitly convertible to a numpy array. However, the shape check assumes that `other_side` **is** a numpy array (rather than assuming its implicitly convertible to a numpy array, like the expected value is) and so assumes that it has a `shape` attribute (which is not part of how approx [determines if something is a numpy array](https://github.com/pytest-dev/pytest/blob/14437788f07584fcf0578bdb952c720e0b9dd2ab/src/_pytest/python_api.py#L757)).
It seems like either:
1. `ApproxNumpy._repr_compare()` needs to convert `other_side` to a numpy array (ie `_as_numpy_array(other_side)`)
2. `_as_numpy_array` needs to check if the object has a `shape` attribute, if the code is going to assume that's the case
- [x] output of `pip list` from the virtual environment you are using:
Relevant packages:
numpy: 1.26.1
- [x] pytest and operating system versions
pytest: 7.4.3
Ubuntu: 22.04
- [x] minimal example if possible
```
import numpy as np
import pytest
class MyType:
"""Type which is implicitly convertible to a numpy array."""
def __init__(self, vals):
self.vals = vals
def __repr__(self):
return f"{self.__class__.__name__}({self.vals})"
def __array__(self, dtype=None, copy=None):
return np.array(self.vals)
def test_approx_eq():
vec1 = MyType([1.0, 2.0, 3.0])
vec2 = MyType([1.0, 2.0, 4.0])
assert vec1 == pytest.approx(vec2)
```
author:
url:https://github.com/ascended121
type:Person
name:ascended121
datePublished:2024-03-12T18:15:35.000Z
interactionStatistic:
type:InteractionCounter
interactionType:https://schema.org/CommentAction
userInteractionCount:4
url:https://github.com/12114/pytest/issues/12114
context:https://schema.org
headline:Attribute error in pytest.approx for types implicitly convertible to numpy arrays
articleBody:- [x] a detailed description of the bug or problem you are having
When using pytest.approx with custom types which are implicitly convertible to numpy arrays, the following error is observed:
```
E AssertionError: assert <test_matrix_...x7f9169ac4ca0> == approx([1.0 ยฑ....0 ยฑ 4.0e-06])
E (pytest_assertion plugin: representation of details failed: ~/.venv/lib/python3.10/site-packages/_pytest/python_api.py:175: AttributeError: 'MyType' object has no attribute 'shape'.
E Probably an object has a faulty __repr__.)
```
Note: The line number in the error message is a little off from the current head. That line is [here](https://github.com/pytest-dev/pytest/blob/14437788f07584fcf0578bdb952c720e0b9dd2ab/src/_pytest/python_api.py#L166).
Looking at the code, `pytest.approx` sensibly chooses the numpy implementation `ApproxNumpy`, because the expected value is implicitly convertible to a numpy array. However, the shape check assumes that `other_side` **is** a numpy array (rather than assuming its implicitly convertible to a numpy array, like the expected value is) and so assumes that it has a `shape` attribute (which is not part of how approx [determines if something is a numpy array](https://github.com/pytest-dev/pytest/blob/14437788f07584fcf0578bdb952c720e0b9dd2ab/src/_pytest/python_api.py#L757)).
It seems like either:
1. `ApproxNumpy._repr_compare()` needs to convert `other_side` to a numpy array (ie `_as_numpy_array(other_side)`)
2. `_as_numpy_array` needs to check if the object has a `shape` attribute, if the code is going to assume that's the case
- [x] output of `pip list` from the virtual environment you are using:
Relevant packages:
numpy: 1.26.1
- [x] pytest and operating system versions
pytest: 7.4.3
Ubuntu: 22.04
- [x] minimal example if possible
```
import numpy as np
import pytest
class MyType:
"""Type which is implicitly convertible to a numpy array."""
def __init__(self, vals):
self.vals = vals
def __repr__(self):
return f"{self.__class__.__name__}({self.vals})"
def __array__(self, dtype=None, copy=None):
return np.array(self.vals)
def test_approx_eq():
vec1 = MyType([1.0, 2.0, 3.0])
vec2 = MyType([1.0, 2.0, 4.0])
assert vec1 == pytest.approx(vec2)
```
author:
url:https://github.com/ascended121
type:Person
name:ascended121
datePublished:2024-03-12T18:15:35.000Z
interactionStatistic:
type:InteractionCounter
interactionType:https://schema.org/CommentAction
userInteractionCount:4
url:https://github.com/12114/pytest/issues/12114
Person:
url:https://github.com/ascended121
name:ascended121
url:https://github.com/ascended121
name:ascended121
InteractionCounter:
interactionType:https://schema.org/CommentAction
userInteractionCount:4
interactionType:https://schema.org/CommentAction
userInteractionCount:4
External Links {๐}(2)
Analytics and Tracking {๐}
- Site Verification - Google
Libraries {๐}
- Clipboard.js
- D3.js
- Lodash
Emails and Hosting {โ๏ธ}
Mail Servers:
- aspmx.l.google.com
- alt1.aspmx.l.google.com
- alt2.aspmx.l.google.com
- alt3.aspmx.l.google.com
- alt4.aspmx.l.google.com
Name Servers:
- dns1.p08.nsone.net
- dns2.p08.nsone.net
- dns3.p08.nsone.net
- dns4.p08.nsone.net
- ns-1283.awsdns-32.org
- ns-1707.awsdns-21.co.uk
- ns-421.awsdns-52.com
- ns-520.awsdns-01.net