Skip to content

Fix setting of fill_value for string columns in Python 3 - #2733

Merged
rgommers merged 2 commits into
numpy:masterfrom
astrofrog:fix-fill-value-python3
Nov 21, 2012
Merged

rgommers merged 2 commits into
numpy:masterfrom
astrofrog:fix-fill-value-python3

Conversation

@astrofrog

Copy link
Copy Markdown
Contributor

As first discovered in astropy/astropy#451 by @taldcroft, there is a bug with setting the fill value of a string array in MaskedArray with Python 3.x:

In [37]: d = ma.array(['w', 'y', 'z'], mask=[1,0,0])

In [38]: d
Out[38]: 
masked_array(data = [-- y z],
             mask = [ True False False],
       fill_value = N/A)


In [39]: d.fill_value='X'

In [40]: d
Out[40]: 
masked_array(data = [-- y z],
             mask = [ True False False],
       fill_value = N/A)

The attached code fixes this.

@rgommers

Copy link
Copy Markdown
Member

Fix looks OK, two minor points:

  • the assert should be changed to np.testing.assert_.
  • could you change the test docstring to # Regression test for #2733 (now it hides the test name when running test(verbose=2).

@astrofrog

Copy link
Copy Markdown
Contributor Author

@rgommers - do you mean that it should be:

    def test_set_fill_value_unicode_py3(self):
        """
        # Regression test for #2733
        """

or

    def test_set_fill_value_unicode_py3(self):
        # Regression test for #2733

The way I had it was the same as for the other regression tests, and the output with verbose=2 is currently:

Ticket #1559 ... ok
Ticket #61 ... ok
Ticket #17 ... ok
Ticket #254 ... ok
Ticket #271 ... ok
Ticket #1256 ... ok
Ticket #62 ... ok
Ticket #2733 ... ok

for the test_regression.py file, so changing just the test in this PR would make it inconsistent with the others. What do you think?

@rgommers

Copy link
Copy Markdown
Member

I meant the latter. But if that file has many similar issues, it's fine to leave it as is now. I'll fix it once I get annoyed again by not being able to find some failing test quickly.

rgommers pushed a commit that referenced this pull request Nov 21, 2012
Fix setting of fill_value for string columns in Python 3
@rgommers
rgommers merged commit 20224ea into numpy:master Nov 21, 2012
@rgommers

Copy link
Copy Markdown
Member

OK, merged. Thanks @astrofrog

@rgommers

Copy link
Copy Markdown
Member

@certik any objection to backporting this?

@certik

certik commented Dec 6, 2012

Copy link
Copy Markdown
Contributor

No objections.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants