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

Rewrite of tables. #58

Merged
merged 3 commits into from
Feb 9, 2018
Merged

Rewrite of tables. #58

merged 3 commits into from
Feb 9, 2018

Conversation

tpapp
Copy link
Collaborator

@tpapp tpapp commented Feb 7, 2018

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:

  • 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

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-io
Copy link

codecov-io commented Feb 7, 2018

Codecov Report

Merging #58 into master will increase coverage by 2.97%.
The diff coverage is 90.78%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
src/utilities.jl 92.45% <100%> (+0.61%) ⬆️
src/PGFPlotsX.jl 58.33% <87.5%> (+8.33%) ⬆️
src/axiselements.jl 91.39% <89.79%> (+2.42%) ⬆️
src/requires.jl 84.84% <93.33%> (+22.34%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c4d07af...b685411. Read the comment docs.

@tpapp tpapp mentioned this pull request Feb 7, 2018
src/requires.jl Outdated
end

function PGFPlotsX.table_fields(histogram::StatsBase.Histogram{T, 2}) where T
PGFPlotsX.table_fields(midpoints(histogram.edges[1]),
Copy link
Owner

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
Copy link
Owner

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.

Copy link
Collaborator Author

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.
Copy link
Owner

Choose a reason for hiding this comment

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

Is this enforced anywhere?

Copy link
Collaborator Author

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.

print(io, s[1], " ")
push!(vs, s[2])
end
struct TableFile <: OptionType
Copy link
Owner

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).

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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
Copy link
Owner

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will do.


![](table-named-columns.svg)

or a dictionary, here renamed using options:
Copy link
Owner

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.
"""
TableFile(path::AbstractString) = TableFile(OrderedDict{Any, Any}(), path)
Table(options::OrderedDict{Any, Any}, path::AbstractString) =
Copy link
Owner

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.

Copy link
Collaborator Author

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?

Copy link
Owner

Choose a reason for hiding this comment

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

Sure, go ahead.

@tpapp tpapp merged commit 4211f29 into master Feb 9, 2018
@tpapp tpapp deleted the tp/table-rewrite branch February 9, 2018 13:03
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.

None yet

3 participants