Last active
April 11, 2022 14:43
-
-
Save digital-carver/ef1763008768d9f0be5f115906d1994a to your computer and use it in GitHub Desktop.
Discount markdown parser testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h3><code>Tables.columns</code> usage</h3> | |
<p><pre><code class=", now let's take a look at a case utlizing [`Tables.columns`](@ref)."> | |
The following code is taken from the [DataFrames.jl](https://github.com/JuliaData/DataFrames.jl/blob/master/src/other/tables.jl) | |
Tables.jl implementation: | |
</code></pre> | |
getvector(x::AbstractVector) = x | |
getvector(x) = collect(x)</p> | |
<h1>note that copycols is ignored in this definition (Tables.CopiedColumns implies copies have already been made)</h1> | |
<p>fromcolumns(x::Tables.CopiedColumns, names; copycols::Bool=true) = | |
DataFrame(AbstractVector[getvector(Tables.getcolumn(x, nm) for nm in names], | |
Index(names), | |
copycols=false) | |
[…] | |
<pre><code> | |
So here we have a generic `DataFrame` constructor that takes a single, untyped argument, | |
</code></pre> | |
It then passes the <a href="@ref"><code>Tables.AbstractColumns</code></a>-compatible object to an internal function <code>fromcolumns</code>, | |
which dispatches on a special kind of <code>Tables.AbstractColumns</code> object called a <a href="@ref"><code>Tables.CopiedColumns</code></a>,</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h3 dir="auto"><code>Tables.columns</code> usage</h3> | |
<p dir="auto">Ok, now let's take a look at a case utlizing <a href="@ref"><code>Tables.columns</code></a>.<br> | |
The following code is taken from the <a href="https://github.com/JuliaData/DataFrames.jl/blob/master/src/other/tables.jl">DataFrames.jl</a><br> | |
Tables.jl implementation:</p> | |
<div class="highlight highlight-source-julia position-relative overflow-auto"><pre><span class="pl-en">getvector</span>(x<span class="pl-k">::</span><span class="pl-c1">AbstractVector</span>) <span class="pl-k">=</span> x | |
<span class="pl-en">getvector</span>(x) <span class="pl-k">=</span> <span class="pl-c1">collect</span>(x) | |
<span class="pl-c"><span class="pl-c">#</span> note that copycols is ignored in this definition (Tables.CopiedColumns implies copies have already been made)</span> | |
<span class="pl-en">fromcolumns</span>(x<span class="pl-k">::</span><span class="pl-c1">Tables.CopiedColumns</span>, names; copycols<span class="pl-k">::</span><span class="pl-c1">Bool</span><span class="pl-k">=</span><span class="pl-c1">true</span>) <span class="pl-k">=</span> | |
<span class="pl-c1">DataFrame</span>(AbstractVector[<span class="pl-c1">getvector</span>(Tables<span class="pl-k">.</span><span class="pl-c1">getcolumn</span>(x, nm) <span class="pl-k">for</span> nm <span class="pl-k">in</span> names], | |
<span class="pl-c1">Index</span>(names), | |
copycols<span class="pl-k">=</span><span class="pl-c1">false</span>) | |
[<span class="pl-k">...</span>]</pre><div class="zeroclipboard-container position-absolute right-0 top-0"> | |
<clipboard-copy aria-label="Copy" class="ClipboardButton btn js-clipboard-copy m-2 p-0 tooltipped-no-delay" data-copy-feedback="Copied!" data-tooltip-direction="w" value="getvector(x::AbstractVector) = x | |
getvector(x) = collect(x) | |
# note that copycols is ignored in this definition (Tables.CopiedColumns implies copies have already been made) | |
fromcolumns(x::Tables.CopiedColumns, names; copycols::Bool=true) = | |
DataFrame(AbstractVector[getvector(Tables.getcolumn(x, nm) for nm in names], | |
Index(names), | |
copycols=false) | |
[...]" tabindex="0" role="button"> | |
<svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-copy js-clipboard-copy-icon m-2"> | |
<path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path> | |
</svg> | |
<svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-check js-clipboard-check-icon color-fg-success d-none m-2"> | |
<path fill-rule="evenodd" d="M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 01-1.06 0L2.22 9.28a.75.75 0 011.06-1.06L6 10.94l6.72-6.72a.75.75 0 011.06 0z"></path> | |
</svg> | |
</clipboard-copy> | |
</div></div> | |
<p dir="auto">So here we have a generic <code>DataFrame</code> constructor that takes a single, untyped argument,<br> | |
calls <a href="@ref"><code>Tables.columns</code></a> on it, then <a href="@ref"><code>Tables.columnnames</code></a> to get the column names.<br> | |
It then passes the <a href="@ref"><code>Tables.AbstractColumns</code></a>-compatible object to an internal function <code>fromcolumns</code>,<br> | |
which dispatches on a special kind of <code>Tables.AbstractColumns</code> object called a <a href="@ref"><code>Tables.CopiedColumns</code></a>,</p> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment