-
Notifications
You must be signed in to change notification settings - Fork 40
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
Rewrite of tables. #58
Conversation
Table code: Complete rewrite. First argument is options, which is optional, the rest is dispatched to various conversion methods. Previous constructors are kept, extended with matrix/edge, named pairs, etc. Printing rewritten, scanlines made explicit. Other, related code: - factored out matrix edge formatting into a common function, used by tables and coordinates - print NaN and +-Inf properly (pgfplots can use it) - Contour and Histogram are now converted into tables with Table. - changed testing for whitespace, introduced a simple field comparison in tests Examples/gallery: - added a new file for various table constructors, and how to omit points, - changed syntax of Table calls accordingly, - added examples for histograms Accidental fix: - make `print_tex` work for `AbstractString`, it failed on a `CategoricalString` from a dataframe in the gallery
Codecov Report
@@ Coverage Diff @@
## master #58 +/- ##
==========================================
+ Coverage 74.94% 77.91% +2.97%
==========================================
Files 8 8
Lines 443 471 +28
==========================================
+ Hits 332 367 +35
+ Misses 111 104 -7
Continue to review full report at Codecov.
|
src/requires.jl
Outdated
end | ||
|
||
function PGFPlotsX.table_fields(histogram::StatsBase.Histogram{T, 2}) where T | ||
PGFPlotsX.table_fields(midpoints(histogram.edges[1]), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
midpoints
seems deprecated from looking at the generated docs:
WARNING: midpoints(r::Range) is deprecated, use r[1:length(r) - 1] + 0.5 * step(r) instead.
Stacktrace:
[1] depwarn(::String, ::Symbol) at ./deprecated.jl:70
[2] midpoints(::StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}) at ./deprecated.jl:57
[3] table_fields(::StatsBase.Histogram{Int64,2,Tuple{StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}},StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}}}) at /Users/kristoffer/Dropbox/julia/PGFPlotsX/src/requires.jl:62
[4] #Table#42(::Array{Any,1}, ::Type{T} where T, ::StatsBase.Histogram{Int64,2,Tuple{StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}},StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}}}, ::Vararg{StatsBase.Histogram{Int64,2,Tuple{StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}},StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}}},N} where N) at /Users/kristoffer/Dropbox/julia/PGFPlotsX/src/axiselements.jl:458
[5] PGFPlotsX.Table(::StatsBase.Histogram{Int64,2,Tuple{StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}},StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}}}) at /Users/kristoffer/Dropbox/julia/PGFPlotsX/src/axiselements.jl:458
[6] eval(::Module, ::Any) at ./boot.jl:235
test/runtests.jl
Outdated
@@ -2,6 +2,7 @@ using PGFPlotsX | |||
using Base.Test | |||
using Compat | |||
using DataStructures: OrderedDict | |||
using DataFrames |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should make sure to using
all deps here because otherwise we get recompilation messages in the generated documentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, will do.
$SIGNATURES | ||
|
||
Named columns provided as a vector of pairs, eg `[:x => 1:10, :y => 11:20]`. | ||
Symbols or strings are accepted as column names. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this enforced anywhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, currently in the method dispatch.
src/axiselements.jl
Outdated
print(io, s[1], " ") | ||
push!(vs, s[2]) | ||
end | ||
struct TableFile <: OptionType |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the reason over just e.g. Table(path)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean Table(path)
constructing a TableFile
, or simply storing the path
in a Table
?
I have in mind an interface for writing Table
data into files and returning an appropriate TableFile
, ie externalizing tables, for larger datasets, but plan to explore this later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am now convinced that it is best if we keep very close to the syntax of pgfplots
, so I modified code to use the Table
constructor for these. Thanks!
src/requires.jl
Outdated
end | ||
end | ||
hcat(colx, coly, colz), ["x", "y", "z"], cumsum(ns) | ||
end | ||
end | ||
|
||
# TODO: Check if the bins are completely correct |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this comment be removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do.
docs/src/examples/tables.md
Outdated
|
||
![](table-named-columns.svg) | ||
|
||
or a dictionary, here renamed using options: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the reason for including a Dict
constructor. Since the ordering is unknown, is that a good idea?
1. Removed `<: Associative` constructor for `Table`, since the order may not be well defined. Removed `Dict` from examples. 2. Introduced a workaround for midpoints, as their status is unclear ATM. 3. `using` packages we need to generate the manual, to suppress compilation messages.
This keeps the vocabulary of this library close to `pgfplots`. Also convert paths to absolute if necessary, otherwise they will not be found when compiling from temporary files.
src/axiselements.jl
Outdated
""" | ||
TableFile(path::AbstractString) = TableFile(OrderedDict{Any, Any}(), path) | ||
Table(options::OrderedDict{Any, Any}, path::AbstractString) = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a tiny bit weird that the Table
constructor does not return a Table
. However, in practice, I don't think it matters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This allows dispatching print_tex
on the type.
If this was the last issue and you don't mind it this way, can we merge?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, go ahead.
Table code:
A step in fixing #44. Complete rewrite of
Table
. First argument is options, which is optional, the rest is dispatched to various conversion methods. Previous constructors are kept, extended with matrix/edge, named pairs, etc. Printing rewritten, scanlines made explicit.Other, related code:
NaN
and +-Inf
properly (pgfplots
can use it)Contour
andHistogram
are now converted into tables withTable
.Examples/gallery:
Table
calls accordingly,Accidental fix:
print_tex
work forAbstractString
, it failed on aCategoricalString
from a dataframe in the gallery