Skip to content

Commit

Permalink
Deploying to gh-pages from @ 32f61ab 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
jkanche committed Oct 25, 2024
1 parent a8ef94f commit 28edade
Show file tree
Hide file tree
Showing 33 changed files with 5,054 additions and 1,272 deletions.
2 changes: 1 addition & 1 deletion .buildinfo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: f9edf2e2abdbc18b50435a081bfc6821
config: 7077f0accd36916270d8044f72ff5ae3
tags: 645f666f9bcd5a90fca523b33c5a78b7
26 changes: 17 additions & 9 deletions _modules/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta name="color-scheme" content="light dark"><link rel="index" title="Index" href="../genindex.html" /><link rel="search" title="Search" href="../search.html" />

<!-- Generated with Sphinx 7.4.7 and Furo 2024.08.06 -->
<title>Overview: module code - rds2py 0.4.6 documentation</title>
<title>Overview: module code - rds2py 0.5.0 documentation</title>
<link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=fa44fd50" />
<link rel="stylesheet" type="text/css" href="../_static/styles/furo.css?v=354aac6f" />
<link rel="stylesheet" type="text/css" href="../_static/styles/furo-extensions.css?v=302659d7" />
Expand Down Expand Up @@ -165,7 +165,7 @@
</label>
</div>
<div class="header-center">
<a href="../index.html"><div class="brand">rds2py 0.4.6 documentation</div></a>
<a href="../index.html"><div class="brand">rds2py 0.5.0 documentation</div></a>
</div>
<div class="header-right">
<div class="theme-toggle-container theme-toggle-header">
Expand All @@ -189,7 +189,7 @@
<div class="sidebar-sticky"><a class="sidebar-brand" href="../index.html">


<span class="sidebar-brand-text">rds2py 0.4.6 documentation</span>
<span class="sidebar-brand-text">rds2py 0.5.0 documentation</span>

</a><form class="sidebar-search-container" method="get" action="../search.html" role="search">
<input class="sidebar-search" placeholder="Search" name="q" aria-label="Search">
Expand Down Expand Up @@ -244,11 +244,19 @@
<article role="main" id="furo-main-content">
<h1>All modules for which code is available</h1>
<ul><li><a href="rds2py/PyRdsReader.html">rds2py.PyRdsReader</a></li>
<li><a href="rds2py/granges.html">rds2py.granges</a></li>
<li><a href="rds2py/interface.html">rds2py.interface</a></li>
<li><a href="rds2py/parser.html">rds2py.parser</a></li>
<li><a href="rds2py/pdf.html">rds2py.pdf</a></li>
<li><a href="rds2py/rds_parser.html">rds2py.rds_parser</a></li>
<li><a href="rds2py/generics.html">rds2py.generics</a></li>
<li><a href="rds2py/lib_rds_parser.html">rds2py.lib_rds_parser</a></li>
<li><a href="rds2py/rdsutils.html">rds2py.rdsutils</a></li>
<li><a href="rds2py/read_atomic.html">rds2py.read_atomic</a></li>
<li><a href="rds2py/read_dict.html">rds2py.read_dict</a></li>
<li><a href="rds2py/read_factor.html">rds2py.read_factor</a></li>
<li><a href="rds2py/read_frame.html">rds2py.read_frame</a></li>
<li><a href="rds2py/read_granges.html">rds2py.read_granges</a></li>
<li><a href="rds2py/read_mae.html">rds2py.read_mae</a></li>
<li><a href="rds2py/read_matrix.html">rds2py.read_matrix</a></li>
<li><a href="rds2py/read_rle.html">rds2py.read_rle</a></li>
<li><a href="rds2py/read_sce.html">rds2py.read_sce</a></li>
<li><a href="rds2py/read_se.html">rds2py.read_se</a></li>
</ul>
</article>
</div>
Expand Down Expand Up @@ -281,7 +289,7 @@ <h1>All modules for which code is available</h1>

</aside>
</div>
</div><script src="../_static/documentation_options.js?v=03f3338f"></script>
</div><script src="../_static/documentation_options.js?v=1dd76d02"></script>
<script src="../_static/doctools.js?v=9a2dae69"></script>
<script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="../_static/scripts/furo.js?v=5fa4622c"></script>
Expand Down
109 changes: 88 additions & 21 deletions _modules/rds2py/PyRdsReader.html

Large diffs are not rendered by default.

426 changes: 426 additions & 0 deletions _modules/rds2py/generics.html

Large diffs are not rendered by default.

553 changes: 0 additions & 553 deletions _modules/rds2py/interface.html

This file was deleted.

356 changes: 356 additions & 0 deletions _modules/rds2py/rdsutils.html

Large diffs are not rendered by default.

410 changes: 410 additions & 0 deletions _modules/rds2py/read_atomic.html

Large diffs are not rendered by default.

335 changes: 335 additions & 0 deletions _modules/rds2py/read_dict.html

Large diffs are not rendered by default.

103 changes: 39 additions & 64 deletions _modules/rds2py/pdf.html → _modules/rds2py/read_factor.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta name="color-scheme" content="light dark"><link rel="index" title="Index" href="../../genindex.html" /><link rel="search" title="Search" href="../../search.html" />

<!-- Generated with Sphinx 7.4.7 and Furo 2024.08.06 -->
<title>rds2py.pdf - rds2py 0.4.6 documentation</title>
<title>rds2py.read_factor - rds2py 0.5.0 documentation</title>
<link rel="stylesheet" type="text/css" href="../../_static/pygments.css?v=fa44fd50" />
<link rel="stylesheet" type="text/css" href="../../_static/styles/furo.css?v=354aac6f" />
<link rel="stylesheet" type="text/css" href="../../_static/styles/furo-extensions.css?v=302659d7" />
Expand Down Expand Up @@ -165,7 +165,7 @@
</label>
</div>
<div class="header-center">
<a href="../../index.html"><div class="brand">rds2py 0.4.6 documentation</div></a>
<a href="../../index.html"><div class="brand">rds2py 0.5.0 documentation</div></a>
</div>
<div class="header-right">
<div class="theme-toggle-container theme-toggle-header">
Expand All @@ -189,7 +189,7 @@
<div class="sidebar-sticky"><a class="sidebar-brand" href="../../index.html">


<span class="sidebar-brand-text">rds2py 0.4.6 documentation</span>
<span class="sidebar-brand-text">rds2py 0.5.0 documentation</span>

</a><form class="sidebar-search-container" method="get" action="../../search.html" role="search">
<input class="sidebar-search" placeholder="Search" name="q" aria-label="Search">
Expand Down Expand Up @@ -242,84 +242,59 @@
</label>
</div>
<article role="main" id="furo-main-content">
<h1>Source code for rds2py.pdf</h1><div class="highlight"><pre>
<span></span><span class="kn">from</span> <span class="nn">.parser</span> <span class="kn">import</span> <span class="n">get_class</span>
<h1>Source code for rds2py.read_factor</h1><div class="highlight"><pre>
<span></span><span class="sd">&quot;&quot;&quot;Functions for parsing R factor objects.</span>

<span class="sd">This module handles the conversion of R factors (categorical variables) into Python lists, preserving the levels and</span>
<span class="sd">maintaining the order of the factor levels.</span>
<span class="sd">&quot;&quot;&quot;</span>

<span class="kn">from</span> <span class="nn">.generics</span> <span class="kn">import</span> <span class="n">_dispatcher</span>
<span class="kn">from</span> <span class="nn">.rdsutils</span> <span class="kn">import</span> <span class="n">get_class</span>

<span class="n">__author__</span> <span class="o">=</span> <span class="s2">&quot;jkanche&quot;</span>
<span class="n">__copyright__</span> <span class="o">=</span> <span class="s2">&quot;jkanche&quot;</span>
<span class="n">__license__</span> <span class="o">=</span> <span class="s2">&quot;MIT&quot;</span>


<div class="viewcode-block" id="as_pandas_from_data_frame">
<a class="viewcode-back" href="../../api/rds2py.html#rds2py.pdf.as_pandas_from_data_frame">[docs]</a>
<span class="k">def</span> <span class="nf">as_pandas_from_data_frame</span><span class="p">(</span><span class="n">robj</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Read an R object to a :py:class:`~pandas.DataFrame`.</span>

<span class="sd"> Args:</span>
<span class="sd"> robj:</span>
<span class="sd"> Object parsed from the `RDS` file.</span>

<span class="sd"> Usually the result of :py:func:`~rds2py.parser.read_rds`.</span>

<span class="sd"> Returns:</span>
<span class="sd"> A `DataFrame` from the R Object.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="kn">from</span> <span class="nn">pandas</span> <span class="kn">import</span> <span class="n">DataFrame</span>

<span class="bp">cls</span> <span class="o">=</span> <span class="n">get_class</span><span class="p">(</span><span class="n">robj</span><span class="p">)</span>

<span class="k">if</span> <span class="bp">cls</span> <span class="o">!=</span> <span class="s2">&quot;data.frame&quot;</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s2">&quot;`robj` does not contain a &#39;data.frame&#39;.&quot;</span><span class="p">)</span>

<span class="n">df</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="p">(</span>
<span class="n">robj</span><span class="p">[</span><span class="s2">&quot;data&quot;</span><span class="p">],</span>
<span class="n">columns</span><span class="o">=</span><span class="n">robj</span><span class="p">[</span><span class="s2">&quot;attributes&quot;</span><span class="p">][</span><span class="s2">&quot;names&quot;</span><span class="p">][</span><span class="s2">&quot;data&quot;</span><span class="p">],</span>
<span class="n">index</span><span class="o">=</span><span class="n">robj</span><span class="p">[</span><span class="s2">&quot;attributes&quot;</span><span class="p">][</span><span class="s2">&quot;row.names&quot;</span><span class="p">][</span><span class="s2">&quot;data&quot;</span><span class="p">],</span>
<span class="p">)</span>

<span class="k">return</span> <span class="n">df</span></div>



<div class="viewcode-block" id="as_pandas_from_dframe">
<a class="viewcode-back" href="../../api/rds2py.html#rds2py.pdf.as_pandas_from_dframe">[docs]</a>
<span class="k">def</span> <span class="nf">as_pandas_from_dframe</span><span class="p">(</span><span class="n">robj</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Convert a realized R object to a pandas data frame representation.</span>
<div class="viewcode-block" id="read_factor">
<a class="viewcode-back" href="../../api/rds2py.html#rds2py.read_factor.read_factor">[docs]</a>
<span class="k">def</span> <span class="nf">read_factor</span><span class="p">(</span><span class="n">robject</span><span class="p">:</span> <span class="nb">dict</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">list</span><span class="p">:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Convert an R factor to a Python list.</span>

<span class="sd"> Args:</span>
<span class="sd"> robj:</span>
<span class="sd"> Object parsed from the `RDS` file.</span>
<span class="sd"> robject:</span>
<span class="sd"> Dictionary containing parsed R factor data.</span>

<span class="sd"> Usually the result of :py:func:`~rds2py.parser.read_rds`.</span>
<span class="sd"> **kwargs:</span>
<span class="sd"> Additional arguments.</span>

<span class="sd"> Returns:</span>
<span class="sd"> A `DataFrame` from the R Object.</span>
<span class="sd"> A list containing the factor values, with each value repeated</span>
<span class="sd"> according to its length if specified.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="kn">from</span> <span class="nn">pandas</span> <span class="kn">import</span> <span class="n">DataFrame</span>

<span class="bp">cls</span> <span class="o">=</span> <span class="n">get_class</span><span class="p">(</span><span class="n">robj</span><span class="p">)</span>
<span class="n">_cls</span> <span class="o">=</span> <span class="n">get_class</span><span class="p">(</span><span class="n">robject</span><span class="p">)</span>

<span class="k">if</span> <span class="bp">cls</span> <span class="o">!=</span> <span class="s2">&quot;DFrame&quot;</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s2">&quot;`robj` does not contain a &#39;DFrame&#39;.&quot;</span><span class="p">)</span>
<span class="k">if</span> <span class="n">_cls</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;factor&quot;</span><span class="p">]:</span>
<span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;`robject` does not contain not a factor object, contains `</span><span class="si">{</span><span class="n">_cls</span><span class="si">}</span><span class="s2">`.&quot;</span><span class="p">)</span>

<span class="n">data</span> <span class="o">=</span> <span class="p">{}</span>
<span class="n">col_names</span> <span class="o">=</span> <span class="n">robj</span><span class="p">[</span><span class="s2">&quot;attributes&quot;</span><span class="p">][</span><span class="s2">&quot;listData&quot;</span><span class="p">][</span><span class="s2">&quot;attributes&quot;</span><span class="p">][</span><span class="s2">&quot;names&quot;</span><span class="p">][</span><span class="s2">&quot;data&quot;</span><span class="p">]</span>
<span class="k">for</span> <span class="n">idx</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">col_names</span><span class="p">)):</span>
<span class="n">idx_asy</span> <span class="o">=</span> <span class="n">robj</span><span class="p">[</span><span class="s2">&quot;attributes&quot;</span><span class="p">][</span><span class="s2">&quot;listData&quot;</span><span class="p">][</span><span class="s2">&quot;data&quot;</span><span class="p">][</span><span class="n">idx</span><span class="p">]</span>
<span class="n">data</span> <span class="o">=</span> <span class="n">robject</span><span class="p">[</span><span class="s2">&quot;data&quot;</span><span class="p">]</span>

<span class="n">data</span><span class="p">[</span><span class="n">col_names</span><span class="p">[</span><span class="n">idx</span><span class="p">]]</span> <span class="o">=</span> <span class="n">idx_asy</span><span class="p">[</span><span class="s2">&quot;data&quot;</span><span class="p">]</span>
<span class="n">levels</span> <span class="o">=</span> <span class="kc">None</span>
<span class="k">if</span> <span class="s2">&quot;levels&quot;</span> <span class="ow">in</span> <span class="n">robject</span><span class="p">[</span><span class="s2">&quot;attributes&quot;</span><span class="p">]:</span>
<span class="n">levels</span> <span class="o">=</span> <span class="n">_dispatcher</span><span class="p">(</span><span class="n">robject</span><span class="p">[</span><span class="s2">&quot;attributes&quot;</span><span class="p">][</span><span class="s2">&quot;levels&quot;</span><span class="p">],</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="n">level_vec</span> <span class="o">=</span> <span class="p">[</span><span class="n">levels</span><span class="p">[</span><span class="n">x</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">data</span><span class="p">]</span>

<span class="n">index</span> <span class="o">=</span> <span class="kc">None</span>
<span class="k">if</span> <span class="n">robj</span><span class="p">[</span><span class="s2">&quot;attributes&quot;</span><span class="p">][</span><span class="s2">&quot;rownames&quot;</span><span class="p">][</span><span class="s2">&quot;data&quot;</span><span class="p">]:</span>
<span class="n">index</span> <span class="o">=</span> <span class="n">robj</span><span class="p">[</span><span class="s2">&quot;attributes&quot;</span><span class="p">][</span><span class="s2">&quot;rownames&quot;</span><span class="p">][</span><span class="s2">&quot;data&quot;</span><span class="p">]</span>
<span class="k">if</span> <span class="s2">&quot;lengths&quot;</span> <span class="ow">in</span> <span class="n">robject</span><span class="p">[</span><span class="s2">&quot;attributes&quot;</span><span class="p">]:</span>
<span class="n">lengths</span> <span class="o">=</span> <span class="n">_dispatcher</span><span class="p">(</span><span class="n">robject</span><span class="p">[</span><span class="s2">&quot;attributes&quot;</span><span class="p">][</span><span class="s2">&quot;lengths&quot;</span><span class="p">],</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">lengths</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>

<span class="n">df</span> <span class="o">=</span> <span class="n">DataFrame</span><span class="p">(</span>
<span class="n">data</span><span class="p">,</span>
<span class="n">columns</span><span class="o">=</span><span class="n">col_names</span><span class="p">,</span>
<span class="n">index</span><span class="o">=</span><span class="n">index</span><span class="p">,</span>
<span class="p">)</span>
<span class="n">final_vec</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">x</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">lengths</span><span class="p">):</span>
<span class="n">final_vec</span><span class="o">.</span><span class="n">extend</span><span class="p">([</span><span class="n">level_vec</span><span class="p">[</span><span class="n">i</span><span class="p">]]</span> <span class="o">*</span> <span class="n">x</span><span class="p">)</span>

<span class="k">return</span> <span class="n">df</span></div>
<span class="k">return</span> <span class="n">final_vec</span></div>

</pre></div>
</article>
Expand Down Expand Up @@ -353,7 +328,7 @@ <h1>Source code for rds2py.pdf</h1><div class="highlight"><pre>

</aside>
</div>
</div><script src="../../_static/documentation_options.js?v=03f3338f"></script>
</div><script src="../../_static/documentation_options.js?v=1dd76d02"></script>
<script src="../../_static/doctools.js?v=9a2dae69"></script>
<script src="../../_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="../../_static/scripts/furo.js?v=5fa4622c"></script>
Expand Down
Loading

0 comments on commit 28edade

Please sign in to comment.