-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Inconsistency in result of comparing unmasked Table column to value #1446
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
Conversation
|
That's pretty odd, thanks for reporting this. I think the desired output in every case is a plain boolean numpy array. I'm not sure if this code path ends up going through |
|
@taldcroft - I think that, as you suggested before, we should look into adapting part of what we learned for |
|
@astrofrog - That would be good. I'm sure your numpy-fu now vastly exceeds our collective knowledge when we did |
|
@mwcraig @taldcroft - I need your feedback here. Currently, the attached fix means that all the examples shown higher up in this issue return a boolean array. Now we need to think a bit more about what the expected behavior should be:
In all cases, I don't think we should ever return a column object, right? Thinking more into the future, how do we deal with cases where the values are the same but the units are different? |
|
@astrofrog - my sense would be to behave just like |
|
@astrofrog - Coming from using atpy I'm used to columns acting like an Though I'd expect to be able to create a column from the result it is hard for me to see how to automatically generate a sensible name/description if the result is a column. As far as units go, with the caveat that I haven't used
|
|
Ok, so now what about the following scenario: comparing two masked columns where the mask is the same and the unmasked values are the same, but where the masked values are not. I think it should return Note that some tests are failing because they were testing e.g. |
|
@astrofrog - maybe for the masked case, the array returned should be masked as well, i.e., you should return |
|
@astrofrog - I agree with @mwcraig that all of the comparisons should return element by element boolean values. I'm a little bit leery of raising an exception when comparing a table column that has units with a plain array. I count myself among the 99% of astronomers that are used to working with arrays with a unit label (or more likely just knowing within the code what units your array value has), rather than our new Quantities. Even though the latter has clear advantages, I don't think adoption within the broad community will be that fast. Until a table column is a Quantity (which is not entirely trivial to make happen) we should not enforce all the Quantity-type behaviors. |
|
@astrofrog - about masking comparisons, your second comment on this matches my expectation. Remember, the value behind the mask should be treated as meaningless. If a value is masked then you don't know the real value so a comparison is likewise "don't know". |
|
@taldcroft @mhvk - thanks for the input! I'll try and make sure this all works like you mentioned. |
|
@mhvk @taldcroft - ok, I think it should all be behaving properly now. Note that we don't need to return a column, an array is sufficient, since it is very easy to create a new column: Also, masking behaves as expected: |
|
@astrofrog - this looks good. I guess ones columns start to hold quantities, there |
|
@taldcroft -- I should have been clear that I'm definitely in the 99% too (or maybe worse, I still don't even have units as labels yet :)). Perhaps a better way to say what I meant is that if a table column has a |
|
I played around this for a bit and this looks good. It reproduces some numpy behavior that I find a little surprising, but I think that reproducing the numpy behavior is fine. @astrofrog - Even though the previous behavior was not desired nor consistent, we should still mark this as an API change in the CHANGES.rst document. Once that is done you can go ahead and merge. |
|
@taldcroft - I added an entry to CHANGES.rst and made a couple of improvements in the test, so let's see what Travis says. Does CHANGES.rst look ok? |
|
CHANGES.rst looks fine. Feel free to merge assuming Travis passes. |
Inconsistency in result of comparing unmasked Table column to value
If I compare a numerical column in a Table to a value (e.g.
t['col0'] == 1wherecol0is numbers) the result is a Column object. If I compare a string column in a Table to a value (e.g.t['col0'] == 'a'wherecol0is strings) the result is a numpyndarray.This specific problem--inconsistency between the returned type based on the data type of the column--does not occur in masked Tables, though there is different bug in that case reported in a separate issue.
The code below reproduces the problem in Anaconda 1.7 and Astropy 0.2.4