TST: DocTestFailure 'MaskedArray' object has no attribute 'unit'
See original GitHub issueHold your horses, @astrofrog and @WilliamJamieson ! We need to fix this before merging more black
stuff. I think one of them broke a doctest. The PRs might be fine individually but maybe didn’t play well together. cc @mhvk
Example log: https://github.com/astropy/astropy/actions/runs/3465731975/jobs/5788828409
_____________________________ [doctest] index.rst ______________________________
119 |Quantity|, but does not share any of its methods. Hence, even though the
120 resulting class looks reasonable at first glance, it does not work as expected::
121
122 >>> q = [1., 2.] * u.m
123 >>> np_mq = np.ma.MaskedArray(q, mask=[False, True])
124 >>> np_mq
125 masked_Quantity(data=[1.0, --],
126 mask=[False, True],
127 fill_value=1e+20)
128 >>> np_mq.unit
Differences (unified diff with -expected +actual):
@@ -1,3 +1,6 @@
Traceback (most recent call last):
-...
-AttributeError: 'MaskedArray' object has no attribute 'unit'
+ File "/opt/hostedtoolcache/Python/3.10.8/x64/lib/python3.10/doctest.py", line 1350, in __run
+ exec(compile(example.source, filename, "single",
+ File "<doctest index.rst[21]>", line 1, in <module>
+ np_mq.unit
+AttributeError: 'MaskedArray' object has no attribute 'unit'. Did you mean: '_unit'?
/home/runner/work/astropy/astropy/docs/utils/masked/index.rst:128: DocTestFailure
Issue Analytics
- State:
- Created 10 months ago
- Comments:13 (10 by maintainers)
Top Results From Across the Web
AttributeError: 'numpy.ndarray' object has no attribute 'units'
I just tried the same metpy package and bumped into the same problem: AttributeError: 'numpy.ndarray' object has no attribute 'units'.
Read more >'sequential' object has no attribute 'predict_classes'. did you ...
Keras AttributeError: 'Sequential' object has no attribute ... astropy/astropyTST: DocTestFailure 'MaskedArray' object has no attribute 'unit'#14005.
Read more >How to Fix: 'numpy.ndarray' object has no attribute 'index'
'numpy.ndarray' object has no attribute 'index' is an attribute error which indicates that there is no index method or attribute available ...
Read more >Constants of the numpy.ma module
It is used to test whether a specific entry of a masked array is masked, ... Value indicating that a masked array has...
Read more >'numpy.ndarray' object has no attribute 'nan_to_num' - Data ...
You are using the right method but in a wrong way :) nan_to_num is a method of numpy module, not numpy.ndarray .
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
or you could do this kind of thing:
note the
...
at the end. this still checks the important part of the message but ignores the suggestions.I don’t know yet why stuff breaks with pytest, if exceptiongroup is to blame I’m happy to look into that more. Just chiming in to say that it’s very much intentional on the CPython side that the suggestions are only computed when printing the traceback. computing the suggestion is relatively costly (it does
dir(obj)
, then computes an edit distance between the wrong attribute and all other attributes) so it would be way too expensive to do that computation on every instantiation of AttributeError, some of which might be caught and never even reach the user.