question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Validation errors

See original GitHub issue

I noticed that there isn’t a single call of .validate() anywhere in the discretize package or testing suite. Perhaps this was overlooked?

I figured this out because I was adding validation checks for MR #114 and I can’t validate any meshes without the following difficult to trace back error (on the master branch):

import discretize
tens = discretize.TensorMesh([16, 16])
tens.validate()
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-2-fc8c65b21a77> in <module>()
      1 import discretize
      2 tens = discretize.TensorMesh([16, 16])
----> 3 tens.validate()

/Users/bane/anaconda3/envs/disc/lib/python2.7/site-packages/properties/base/base.pyc in validate(self)
    409                 )
    410             elif self._non_validation_error:
--> 411                 raise self._non_validation_error                               #pylint: disable=raising-bad-type
    412             return True
    413         finally:

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
prisaecommented, Nov 7, 2018

I think it is a backwards compatibility issue, as at some point you could do this comparison, but they changed it at some point, if I remember right.

I haven’t looked into it in detail, and @rowanc1 or @lheagy are probably better suited to answer that. But at least as a short fix you can probably simply change line 55 from

if change['previous'] != properties.undefined:

to

if np.any(change['previous'] != properties.undefined):

See this dummy example:

In [1]: a = np.arange(10)                                                       

In [2]: b = 4                                                                   

In [3]: if a == b: 
   ...:     print('yes')                                                        
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-4-450e19031455> in <module>
----> 1 if a == b:
      2     print('yes')

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

In [4]: if np.any(a == b): 
   ...:     print('yes')                                                        
yes
0reactions
banesullivancommented, Nov 7, 2018

Here’s another one with the TreeMesh (after fixing line 55 in Base.py as mentioned above)

import discretize
from discretize import utils

tree = discretize.TreeMesh([16, 16])

def refine(cell):
    if np.sqrt(((np.r_[cell.center]-0.5)**2).sum()) < 0.4:
        return 4
    return 3

tree.refine(refine)

tree.validate()

With the following traceback:

---------------------------------------------------------------------------
ValidationError                           Traceback (most recent call last)
<ipython-input-3-4403a86a60ca> in <module>()
     27 
     28 # plt.show()
---> 29 tree.validate()

~/anaconda3/envs/ogv/lib/python3.6/site-packages/properties/base/base.py in validate(self)
    406                 raise utils.ValidationError(
    407                     message='\n- '.join(msgs),
--> 408                     _error_tuples=self._validation_error_tuples,
    409                 )
    410             elif self._non_validation_error:

ValidationError: Validation failed:
- The 'x0' property of a TreeMesh instance is required and has not been set.
Read more comments on GitHub >

github_iconTop Results From Across the Web

Validation errors - Oracle Help Center
Validation errors typically occur when a request is malformed -- usually because a field has not been given the correct value type, or...
Read more >
Form Validation Errors - how to track them and what to do ...
1) a user entered an invalid data into a form field, for example, an email without "@" character · 2) a user entered...
Read more >
Validation-Errors-Warnings - Research and Development
Validation-Errors-Warnings. The Kuali Research validation tool is useful but does not replace the knowledge and skills of a research administrator.
Read more >
Form-Field Validation: The Errors-Only Approach
Error pages for form-field validation are dreadful. You've just filled out 20 form fields, yet you get the same bloated page thrown back...
Read more >
ValidationErrors - Angular
Defines the map of errors returned from failed validation checks. type ValidationErrors = { [key: string]: any; };. Resources.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found