Thanks to visit codestin.com
Credit goes to github.com

Skip to content

BUG: Non-bool result when comparing ma scalars. #4335

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

Closed
wants to merge 1 commit into from

Conversation

abalkin
Copy link
Contributor

@abalkin abalkin commented Feb 20, 2014

Removed logic replacing masked scalar results from ufuncs
with ma.masked singleton which has dtype float64.

Fixes #4332.

Removed logic replacing masked scalar results from ufuncs
with ma.masked singleton which has dtype float64.

Fixes numpy#4332.
else:
result._mask = m
result._sharedmask = False
result._mask = m
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit at sea here. Will this still return scalars in this case, just with the correct type?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning a scalar is very much intended in most of numpy, so I think it is intended here, too, and I would prefer not to change it without good reason. Can't we give masked a type?

@pierregm
Copy link
Contributor

The idea is to return the masked singleton, a scalar MaskedArray. The issue here is that masked has currently a dtype(float64). As mentioned in another conversation, we could try to use dtype(bool_) instead (which might however) lead to some problems of precedence and check whether we're not breaking anything w/ matplotlib before considering this PR (the change is a bit too radical to my taste).

@seberg
Copy link
Member

seberg commented Feb 26, 2014

Oops, I missed the fact that is used as a singleton... Sounds like this is complicated and likely not much can be done.

@abalkin
Copy link
Contributor Author

abalkin commented Feb 26, 2014

@seberg - the traditional use for masked singleton is to check for masked items:

>>> x = np.ma.masked_all(3, dtype='h')
>>> x[1] is np.ma.masked
True

This use case is unaffected by my change.

I find it really hard to justify the following behaviors:

>>> x = np.ma.masked_all((), dtype=bool)
>>> x.dtype
dtype('bool')
>>> (x & True).dtype
dtype('float64')
>>> x.max().dtype
dtype('float64')
>>> (~x).dtype
dtype('float64')

I will run matplotlib tests with the change. I seriously doubt that anyone is using if x is masked test for the result of a ufunc instead of if x.mask or if x.mask.all().

@abalkin
Copy link
Contributor Author

abalkin commented Feb 26, 2014

Here is another wart:

>>> bool(x.sum() is np.ma.masked)
True
>>> bool(x.sum() == np.ma.masked)
False

@seberg
Copy link
Member

seberg commented Feb 26, 2014

Sorry, I really don't know this well. As far as I can see, this adds one wart to fix another and since I don't really use masked arrays, I certainly don't know if that may be worth it.

@charris
Copy link
Member

charris commented Mar 23, 2014

@pierregm Can you comment as to what you think we should do with this?

@charris charris added this to the 1.10.0 release milestone Apr 7, 2015
@charris charris self-assigned this Apr 28, 2015
@charris
Copy link
Member

charris commented May 4, 2015

I'm going to close this. A proper solution would probably be to have masked scalars of all types. That option could use some study, especially preserving backward compatibility.

@charris charris closed this May 4, 2015
@charris
Copy link
Member

charris commented May 4, 2015

Or possibly we could fudge things, adding a type attribute to the current masked scalar or some such nonsense.

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

Successfully merging this pull request may close these issues.

BUG: Masked scalar comparison returns float
5 participants