Skip to content

Conversation

@tylfin
Copy link
Contributor

@tylfin tylfin commented Oct 4, 2016

Fixes #5354

@taldcroft
Copy link
Member

@tylfin - I haven't had a chance to look through this line by line, but overall it looks much better and seems to be on track!

return None
return last_index + 1

def set_fill_values(self, header, cols, fill_values):
Copy link
Member

Choose a reason for hiding this comment

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

I think you might not need this new method as some of the things being set are probably redundant. At the place where this gets called, self.data is the same as self here. So for instance the self.data object already has a copy of header from __init__. So just try moving these statements inline and then remove one-by-one until things break.

The issue is just that all this code is really intricate and intertwined already (sorry), so working hard to minimize complexity is important.

cols = list(six.itervalues(table.columns))

# Set fill_vals on the columns for replacement
HTML.data_class().set_fill_values(self.header, cols, self.data.fill_values)
Copy link
Member

Choose a reason for hiding this comment

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

I think you should be able to use self.data instead of HTML.data_class().

</tr>"""
assert expected in out.getvalue()

def test_write_table_html():
Copy link
Member

Choose a reason for hiding this comment

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

You should also test with a table that has masked values where you set fill_values to [(ascii.masked, 'TEST')] and confirm that the masked table entries are indeed TEST.

</tr>"""
assert expected in out.getvalue()

def test_write_table_html():
Copy link
Member

Choose a reason for hiding this comment

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

Also test with a table that has a multi-dimensional column, i.e. each row is a 1-d array.

@tylfin
Copy link
Contributor Author

tylfin commented Oct 10, 2016

@taldcroft I think I've addressed all the comments you made, tell me if there is anything else!

@taldcroft
Copy link
Member

@tylfin - this is overall much better again, but I think there is a problem in the masked element handling. Can you add a test along the lines of the example below to make sure it passes?

In [18]: t = Table([[1, 2, 3, 4], ['--', 'a', '--', 'b']], names=('a', 'b'), masked=True)

In [19]: t['a'][0:2] = np.ma.masked

In [20]: t['b'][0:2] = np.ma.masked

In [21]: t
Out[21]: 
<Table masked=True length=4>
  a    b  
int64 str2
----- ----
   --   --
   --   --
    3   --
    4    b

In [22]: ascii.write(t, fill_values=[(ascii.masked, 'MASKED')])
a b
MASKED MASKED
MASKED MASKED
3 --
4 b

Test for fill_values ascii html format issue
Test for fill_values ascii html format with optional columns
Test for fill_values ascii html format with masked values
Test for fill_values ascii html format with multidimensional columns
Test for fill_values ascii html format with masked values on multidimensional columns
Add fill_values method on HTML that yields either the values themselves, the filled values, or the masked values
@tylfin
Copy link
Contributor Author

tylfin commented Oct 18, 2016

@taldcroft Should be taken care of now! Refactored the masked values logic & added the example above as a test.

@taldcroft taldcroft added this to the v1.0.11 milestone Oct 19, 2016
@taldcroft
Copy link
Member

@tylfin - looks good, now we just need an update to CHANGES.rst. You should put the following into the 1.0.11 release Bug Fixes section within - io.ascii:

  - Fix a bug where the ``fill_values`` parameter was ignored when writing a
    table to HTML format. [#5379]

@taldcroft taldcroft merged commit 1ed6849 into astropy:master Oct 21, 2016
@taldcroft
Copy link
Member

Thanks @tylfin !!

taldcroft added a commit to taldcroft/astropy that referenced this pull request Dec 2, 2016
eteq pushed a commit that referenced this pull request Dec 21, 2016
Add support for fill_values functionality with ascii html
@eteq eteq modified the milestones: v1.2.2, v1.0.11 Dec 21, 2016
@eteq
Copy link
Member

eteq commented Dec 21, 2016

Unfortunately this PR as-is doesn't seem to be backport-able to 1.0.x, as it uses features that seem to be missing in 1.0.x. A PR directly to the 1.0.x branch addressing this is welcome, though!

@ferrigno
Copy link

ferrigno commented Feb 16, 2017

Hello.
When I try to write a HTML table in which a column is made of lists


copy_table.info
Table masked=True length=2080
name dtype shape unit n_bad
"------------------ ------- ------ ------------ -----"
[....]
SPE_PARS float32 (32,) 0


The call to "fill_values" fails with error:
287 list_of_str=ascii.write(copy_table, format="html", fill_values=(ascii.masked, 'None'))
288 #raw_html_cols= ["NAME", "Position reference"]
289

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/astropy/io/ascii/ui.pyc in write(table, output, format, Writer, fast_writer, **kwargs)
727 return
728
--> 729 lines = writer.write(table)
730
731 # Write the lines to output

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/astropy/io/ascii/html.pyc in write(self, table)
429 new_cols_escaped.append(col_escaped)
430
--> 431 for row in zip(*col_str_iters):
432 with w.tag('tr'):
433 for el, col_escaped in zip(row, new_cols_escaped):

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/astropy/io/ascii/html.pyc in fill_values(self, col, col_str_iters)
452 for idx, col_str in enumerate(col_str_iters):
453 if is_masked_column and has_fill_values:
--> 454 if col.mask[idx]:
455 yield col.fill_values[core.masked]
456 continue

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

I am not familiar enough with python and its coding to find a robust solution. I am sorry

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.

5 participants