Operation on masked_array changes fill_value
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 32.8k
- Forks
- 12.8k
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 197
Description
I first raised this issue on stackoverflow (see link on the bottom)
Seems like the new masked_array should inherit the fill_value from the two masked_arrays being summed?
Can someone explain to me this behavior of a numpy masked_array? It seems to change the fill_value after applying the sum operation, which is confusing if you intend to use the filled result.
data=ones((5,5))
m=zeros((5,5),dtype=bool)
"""Mask out row 3"""
m[3,:]=True
arr=ma.masked_array(data,mask=m,fill_value=nan)
print arr
print 'Fill value:', arr.fill_value
print arr.filled()
farr=arr.sum(axis=1)
print farr
print 'Fill value:', farr.fill_value
print farr.filled()
"""I was expecting this"""
print nansum(arr.filled(),axis=1)
Prints output:
[[1.0 1.0 1.0 1.0 1.0]
[1.0 1.0 1.0 1.0 1.0]
[1.0 1.0 1.0 1.0 1.0]
[-- -- -- -- --]
[1.0 1.0 1.0 1.0 1.0]]
Fill value: nan
[[ 1. 1. 1. 1. 1.]
[ 1. 1. 1. 1. 1.]
[ 1. 1. 1. 1. 1.]
[ nan nan nan nan nan]
[ 1. 1. 1. 1. 1.]]
[5.0 5.0 5.0 -- 5.0]
Fill value: 1e+20
[ 5.00000000e+00 5.00000000e+00 5.00000000e+00 1.00000000e+20
5.00000000e+00]
[ 5. 5. 5. nan 5.]
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No source file or test is named. Start by running the reported masked_array sum and filled() example, then trace the sum result's fill_value handling; done means the behavior matches the documented expectation for the masked row and its filled result.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100