Skip to content

BUG: na_rep given precedence in to_html #13911

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
Closed

BUG: na_rep given precedence in to_html #13911

wants to merge 1 commit into from

Conversation

agraboso
Copy link
Contributor

@agraboso agraboso commented Aug 4, 2016

I know new tests are appreciated from the get-go, but it's the end of the day for me. I'll add new tests and the appropriate whatsnew entry tomorrow.

# na_rep takes precedence over the specified formatter
if self.na_rep is not None:
return np.array([self.formatter(x) if notnull(x)
else self.na_rep for x in self.values])
Copy link
Contributor

Choose a reason for hiding this comment

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

use notnull on the entire array first to create a mask
format the non null values then fill the nans

see the datetime formatters for how to do this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jreback I just looked at the datetime formatters but I don't know what you mean. Could you be more explicit? Thanks.

Copy link
Contributor

Choose a reason for hiding this comment

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

like this (from internals.py)

def to_native_types(self, slicer=None, na_rep=None, quoting=None,
                    **kwargs):
    """ convert to our native types format, slicing if desired """

    values = self.values
    if slicer is not None:
        values = values[:, slicer]
    mask = isnull(values)

    rvalues = np.empty(values.shape, dtype=object)
    if na_rep is None:
        na_rep = 'NaT'
    rvalues[mask] = na_rep
    imask = (~mask).ravel()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See update. Is that what you mean?

@codecov-io
Copy link

codecov-io commented Aug 5, 2016

Current coverage is 84.64% (diff: 90.00%)

Merging #13911 into master will increase coverage by <.01%

@@             master     #13911   diff @@
==========================================
  Files           144        144          
  Lines         51016      51024     +8   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
+ Hits          43184      43191     +7   
- Misses         7832       7833     +1   
  Partials          0          0          

Powered by Codecov. Last update 3ccb501...685c6d2

@jreback jreback added Output-Formatting __repr__ of pandas objects, to_string IO HTML read_html, to_html, Styler.apply, Styler.applymap labels Aug 5, 2016
@sinhrks sinhrks added the Bug label Aug 5, 2016
@agraboso
Copy link
Contributor Author

@jreback I think I understood what you meant by iterating over non-null values. Please have a look.

@agraboso
Copy link
Contributor Author

@jreback

@jreback
Copy link
Contributor

jreback commented Sep 9, 2016

can you rebase / update?

@agraboso
Copy link
Contributor Author

Rebased and all green.

@jreback jreback added this to the 0.19.0 milestone Sep 20, 2016
@jreback
Copy link
Contributor

jreback commented Sep 20, 2016

lgtm. @jorisvandenbossche

@@ -2060,7 +2060,19 @@ def get_result_as_array(self):
"""

if self.formatter is not None:
return np.array([self.formatter(x) for x in self.values])
if self.na_rep is None:
Copy link
Contributor

Choose a reason for hiding this comment

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

you are repeating lots of code from right below format_values_with. see if you can simplify

Copy link
Contributor

Choose a reason for hiding this comment

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

can you update here

@jreback jreback modified the milestones: 0.19.0, 0.19.1 Sep 28, 2016
@jorisvandenbossche jorisvandenbossche modified the milestones: 0.20.0, 0.19.1 Oct 31, 2016
@@ -1524,6 +1524,7 @@ Bug Fixes
- Bug in ``groupby(..).nth()`` where the group key is included inconsistently if called after ``.head()/.tail()`` (:issue:`12839`)
- Bug in ``.to_html``, ``.to_latex`` and ``.to_string`` silently ignore custom datetime formatter passed through the ``formatters`` key word (:issue:`10690`)
- Bug in ``DataFrame.iterrows()``, not yielding a ``Series`` subclasse if defined (:issue:`13977`)
- Bug in ``.to_html``, ``.to_latex`` and ``.to_string`` ignoring ``na_rep`` in the presence of a ``float_format`` function. (:issue:`13911`)
Copy link
Contributor

Choose a reason for hiding this comment

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

can you move to 0.20.0

@jreback
Copy link
Contributor

jreback commented Dec 16, 2016

i think this got lost in the shuffle, can you update.

@agraboso
Copy link
Contributor Author

Rebased, moved whatsnew to 0.20.0, need to look into the code duplication @jreback mentioned.

@jreback
Copy link
Contributor

jreback commented Dec 30, 2016

can you rebase / update

@jreback
Copy link
Contributor

jreback commented Feb 27, 2017

closing as stale. please ping if you'd like to continue.

@jreback jreback closed this Feb 27, 2017
@jreback jreback modified the milestones: No action, 0.20.0 Feb 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug IO HTML read_html, to_html, Styler.apply, Styler.applymap Output-Formatting __repr__ of pandas objects, to_string
Projects
None yet
Development

Successfully merging this pull request may close these issues.

to_html ignores na_rep when float_format set
5 participants