Skip to content
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

Breaking changes in DataFrames master #38

Closed
amellnik opened this issue Oct 5, 2016 · 7 comments
Closed

Breaking changes in DataFrames master #38

amellnik opened this issue Oct 5, 2016 · 7 comments

Comments

@amellnik
Copy link

amellnik commented Oct 5, 2016

DataFrames is moving to Nullables (JuliaData/DataFrames.jl#1092). It looks like Mustache is in pretty good shape, but at a minimum needs to change the way it renders Nullables into templates, as shown below. Opening this issue to track.

using DataFrames, Mustache
tpl = mt"""
<html>
<head>
<title>{{:TITLE}}</title>
</head>
<body>
<table>
<tr><th>name</th><th>summary</th></tr>
{{#:D}}
<tr><td>{{:names}}</td><td>{{:summs}}</td></tr>
{{/:D}}
</body>
</html>
"""

_names = Array(String, 0)
_summaries = Array(String, 0)
m = Main
for s in sort(map(string, names(m)))
    v = symbol(s)
    if isdefined(m,v)
        push!(_names, s)
        push!(_summaries, summary(eval(m,v)))
    end
end

d = DataFrame(names=_names, summs=_summaries)

out = Mustache.render(tpl, TITLE="A quick table", D=d)
print(out)
<html>
<head>
<title>A quick table</title>
</head>
<body>
<table>
<tr><th>name</th><th>summary</th></tr>

<tr><td>Nullable{String}(&quot;AxisAlgorithms&quot;)</td><td>Nullable{String}(&quot;Module&quot;)</td></tr>

<tr><td>Nullable{String}(&quot;Base&quot;)</td><td>Nullable{String}(&quot;Module&quot;)</td></tr>

<tr><td>Nullable{String}(&quot;Calculus&quot;)</td><td>Nullable{String}(&quot;Module&quot;)</td></tr>

...
@jverzani
Copy link
Owner

jverzani commented Oct 5, 2016

Thanks for the heads up!

@nalimilan
Copy link

FWIW, the way to print only the contents of the Nullable and not the type information is to do sprint(x, showcompact). If you also want to remove surrounding quotes when printing Nullable{String}, you'll need a custom function calling print(get(x)) like this one: https://github.com/JuliaStats/DataFrames.jl/blob/725a22602b8b3f6413e35ebdd707b69c4ed7b659/src/abstractdataframe/show.jl#L67

@jverzani
Copy link
Owner

jverzani commented Oct 7, 2016

I think I have this fixed, but can't get the master of DataFrames working to check. I'll merge if this indeed works.

@nalimilan
Copy link

I think I have this fixed, but can't get the master of DataFrames working to check. I'll merge if this indeed works.

What's the failure? It should work AFAIK.

@jverzani
Copy link
Owner

jverzani commented Oct 7, 2016

It was my fault. My METADATA had an issue. I made a change which seems sufficient for this case.

 if isa(value, Nullable)
    value = isnull(value) ? nothing : get(value)
end

Is this the proper way to fish out the value of a Nullable object?

@nalimilan
Copy link

It depends how the code works and what's the intended result. If you want to avoid printing anything for null values, then it's OK, though you could write it more concisely as get(value, nothing). But in other places we print null values as #NULL, which you would get with your original commit.

(BTW, if performance matters in this part of the code, you could make lookup type-stable by changing it to return a Nullable instead of Union{Void, T}.)

@jverzani
Copy link
Owner

jverzani commented Oct 7, 2016

Thanks!

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

No branches or pull requests

3 participants