Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

analyze methods do not allow Y as a list #70

Open
jdherman opened this issue Jul 31, 2015 · 6 comments
Open

analyze methods do not allow Y as a list #70

jdherman opened this issue Jul 31, 2015 · 6 comments

Comments

@jdherman
Copy link
Member

currently required to be a numpy array.

Could add a simple check at the beginning of every method, if type(Y) is list: Y = np.array(Y)

@willu47
Copy link
Member

willu47 commented Jul 31, 2015

Best to use an 'assert' command?

On 31 Jul 2015 8:41 pm, Jon Herman [email protected] wrote:

currently required to be a numpy array.

Could add a simple check at the beginning of every method, if type(Y) is list: Y = np.array(Y)


Reply to this email directly or view it on GitHubhttps://github.com//issues/70.

@jdherman
Copy link
Member Author

Hey Will. Does assert always need to throw an error when the assertion fails? In this case I think it'd be better to silently convert to np.array.

@willu47
Copy link
Member

willu47 commented Aug 1, 2015

I don't think there is any issue with the methods failing if they're not called with the correct type arguments. An assert command would then raise the appropriate error (TypeError), and warn the user. Generally, it is best to fail early and gracefully than try to automatically cope for every possible permutation of types the procedure called be called with.

@dhadka
Copy link
Contributor

dhadka commented Aug 3, 2015

Hey Will. I originally brought this issue up with Jon, as I ran into errors trying to pass in a list. I'd be fine with the software failing, but it should produce a better error message. Below is the current error message:

Traceback (most recent call last):
  File "C:\Program Files (x86)\Python27\lib\site-packages\salib-e315cb0508ded16e92aba9a6c42b1fea41e78e90-py2.7.egg\SALib\analyze\sobol.py", line 21, in analyze
    if calc_second_order and Y.size % (2 * D   2) == 0:
AttributeError: 'list' object has no attribute 'size'

@jdherman
Copy link
Member Author

jdherman commented Aug 3, 2015

Thanks Dave. I don't have a preference either way, as long as all of the methods are modified consistently. (Maybe this falls under the general need for improved error messages).

Something I noticed, numpy will always cast a list to a np-array if you pass it into a function instead of using the object attributes. So for example:

>>> import numpy as np
>>> A = [2, 3, 4, 5]
>>> np.size(A)
4
>>> A.size
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'list' object has no attribute 'size'
>>>

So maybe the easiest thing to do is switch to np.* functions instead of object attributes throughout.

@willu47
Copy link
Member

willu47 commented Aug 4, 2015

Hmm. I understand now. Or we could just create a 'data cleaning' module for when the command-line interface is used. Then the data will be coerced to the correct type before the functions are called.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants