Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Jan 17, 2024
1 parent 82920f5 commit 7757f88
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion _modules/one/alf/cache.html
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ <h1>Source code for one.alf.cache</h1><div class="highlight"><pre>
<span class="kn">from</span> <span class="nn">one.alf.files</span> <span class="kn">import</span> <span class="n">session_path_parts</span><span class="p">,</span> <span class="n">get_alf_path</span>
<span class="kn">from</span> <span class="nn">one.converters</span> <span class="kn">import</span> <span class="n">session_record2path</span>

<span class="n">__all__</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;make_parquet_db&#39;</span><span class="p">,</span> <span class="s1">&#39;remove_missing_datasets&#39;</span><span class="p">]</span>
<span class="n">__all__</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;make_parquet_db&#39;</span><span class="p">,</span> <span class="s1">&#39;remove_missing_datasets&#39;</span><span class="p">,</span> <span class="s1">&#39;DATASETS_COLUMNS&#39;</span><span class="p">,</span> <span class="s1">&#39;SESSIONS_COLUMNS&#39;</span><span class="p">]</span>
<span class="n">_logger</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="vm">__name__</span><span class="p">)</span>

<span class="c1"># -------------------------------------------------------------------------------------------------</span>
Expand Down
8 changes: 5 additions & 3 deletions _modules/one/api.html
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ <h1>Source code for one.api</h1><div class="highlight"><pre>
<span class="kn">import</span> <span class="nn">one.alf.io</span> <span class="k">as</span> <span class="nn">alfio</span>
<span class="kn">import</span> <span class="nn">one.alf.files</span> <span class="k">as</span> <span class="nn">alfiles</span>
<span class="kn">import</span> <span class="nn">one.alf.exceptions</span> <span class="k">as</span> <span class="nn">alferr</span>
<span class="kn">from</span> <span class="nn">.alf.cache</span> <span class="kn">import</span> <span class="n">make_parquet_db</span>
<span class="kn">from</span> <span class="nn">.alf.cache</span> <span class="kn">import</span> <span class="n">make_parquet_db</span><span class="p">,</span> <span class="n">DATASETS_COLUMNS</span><span class="p">,</span> <span class="n">SESSIONS_COLUMNS</span>
<span class="kn">from</span> <span class="nn">.alf.spec</span> <span class="kn">import</span> <span class="n">is_uuid_string</span>
<span class="kn">from</span> <span class="nn">.</span> <span class="kn">import</span> <span class="n">__version__</span>
<span class="kn">from</span> <span class="nn">one.converters</span> <span class="kn">import</span> <span class="n">ConversionMixin</span><span class="p">,</span> <span class="n">session_record2path</span>
Expand Down Expand Up @@ -263,7 +263,9 @@ <h1>Source code for one.api</h1><div class="highlight"><pre>
<span class="c1"># No tables present</span>
<span class="n">meta</span><span class="p">[</span><span class="s1">&#39;expired&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="kc">True</span>
<span class="n">meta</span><span class="p">[</span><span class="s1">&#39;raw&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_cache</span><span class="o">.</span><span class="n">update</span><span class="p">({</span><span class="s1">&#39;datasets&#39;</span><span class="p">:</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(),</span> <span class="s1">&#39;sessions&#39;</span><span class="p">:</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">()})</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_cache</span><span class="o">.</span><span class="n">update</span><span class="p">({</span>
<span class="s1">&#39;datasets&#39;</span><span class="p">:</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">columns</span><span class="o">=</span><span class="n">DATASETS_COLUMNS</span><span class="p">)</span><span class="o">.</span><span class="n">set_index</span><span class="p">([</span><span class="s1">&#39;eid&#39;</span><span class="p">,</span> <span class="s1">&#39;id&#39;</span><span class="p">]),</span>
<span class="s1">&#39;sessions&#39;</span><span class="p">:</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">columns</span><span class="o">=</span><span class="n">SESSIONS_COLUMNS</span><span class="p">)</span><span class="o">.</span><span class="n">set_index</span><span class="p">(</span><span class="s1">&#39;id&#39;</span><span class="p">)})</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">offline</span><span class="p">:</span> <span class="c1"># In online mode, the cache tables should be downloaded later</span>
<span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span><span class="sa">f</span><span class="s1">&#39;No cache tables found in </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">_tables_dir</span><span class="si">}</span><span class="s1">&#39;</span><span class="p">)</span>
<span class="n">created</span> <span class="o">=</span> <span class="p">[</span><span class="n">datetime</span><span class="o">.</span><span class="n">fromisoformat</span><span class="p">(</span><span class="n">x</span><span class="p">[</span><span class="s1">&#39;date_created&#39;</span><span class="p">])</span>
Expand Down Expand Up @@ -412,7 +414,7 @@ <h1>Source code for one.api</h1><div class="highlight"><pre>
<span class="n">to_drop</span> <span class="o">=</span> <span class="nb">set</span><span class="p">(</span><span class="n">records</span><span class="o">.</span><span class="n">columns</span><span class="p">)</span> <span class="o">-</span> <span class="nb">set</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cache</span><span class="p">[</span><span class="n">table</span><span class="p">]</span><span class="o">.</span><span class="n">columns</span><span class="p">)</span>
<span class="n">records</span><span class="o">.</span><span class="n">drop</span><span class="p">(</span><span class="n">to_drop</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">inplace</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="n">records</span> <span class="o">=</span> <span class="n">records</span><span class="o">.</span><span class="n">reindex</span><span class="p">(</span><span class="n">columns</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_cache</span><span class="p">[</span><span class="n">table</span><span class="p">]</span><span class="o">.</span><span class="n">columns</span><span class="p">)</span>
<span class="k">assert</span> <span class="nb">all</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cache</span><span class="p">[</span><span class="n">table</span><span class="p">]</span><span class="o">.</span><span class="n">columns</span> <span class="o">==</span> <span class="n">records</span><span class="o">.</span><span class="n">columns</span><span class="p">)</span>
<span class="k">assert</span> <span class="nb">set</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cache</span><span class="p">[</span><span class="n">table</span><span class="p">]</span><span class="o">.</span><span class="n">columns</span><span class="p">)</span> <span class="o">==</span> <span class="nb">set</span><span class="p">(</span><span class="n">records</span><span class="o">.</span><span class="n">columns</span><span class="p">)</span>
<span class="c1"># Update existing rows</span>
<span class="n">to_update</span> <span class="o">=</span> <span class="n">records</span><span class="o">.</span><span class="n">index</span><span class="o">.</span><span class="n">isin</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cache</span><span class="p">[</span><span class="n">table</span><span class="p">]</span><span class="o">.</span><span class="n">index</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_cache</span><span class="p">[</span><span class="n">table</span><span class="p">]</span><span class="o">.</span><span class="n">loc</span><span class="p">[</span><span class="n">records</span><span class="o">.</span><span class="n">index</span><span class="p">[</span><span class="n">to_update</span><span class="p">],</span> <span class="p">:]</span> <span class="o">=</span> <span class="n">records</span><span class="p">[</span><span class="n">to_update</span><span class="p">]</span>
Expand Down
9 changes: 8 additions & 1 deletion _modules/one/tests/test_one.html
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,14 @@ <h1>Source code for one.tests.test_one</h1><div class="highlight"><pre>
<span class="c1"># Check fringe cases</span>
<span class="k">with</span> <span class="bp">self</span><span class="o">.</span><span class="n">assertRaises</span><span class="p">(</span><span class="ne">KeyError</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">one</span><span class="o">.</span><span class="n">_update_cache_from_records</span><span class="p">(</span><span class="n">unknown</span><span class="o">=</span><span class="n">datasets</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">assertIsNone</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">one</span><span class="o">.</span><span class="n">_update_cache_from_records</span><span class="p">(</span><span class="n">datasets</span><span class="o">=</span><span class="kc">None</span><span class="p">))</span></div>
<span class="bp">self</span><span class="o">.</span><span class="n">assertIsNone</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">one</span><span class="o">.</span><span class="n">_update_cache_from_records</span><span class="p">(</span><span class="n">datasets</span><span class="o">=</span><span class="kc">None</span><span class="p">))</span>
<span class="c1"># Absent cache table</span>
<span class="bp">self</span><span class="o">.</span><span class="n">one</span><span class="o">.</span><span class="n">load_cache</span><span class="p">(</span><span class="n">tables_dir</span><span class="o">=</span><span class="s1">&#39;/foo&#39;</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">one</span><span class="o">.</span><span class="n">_update_cache_from_records</span><span class="p">(</span><span class="n">sessions</span><span class="o">=</span><span class="n">session</span><span class="p">,</span> <span class="n">datasets</span><span class="o">=</span><span class="n">dataset</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">assertTrue</span><span class="p">(</span><span class="nb">all</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">one</span><span class="o">.</span><span class="n">_cache</span><span class="o">.</span><span class="n">sessions</span> <span class="o">==</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">([</span><span class="n">session</span><span class="p">])))</span>
<span class="bp">self</span><span class="o">.</span><span class="n">assertEqual</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">one</span><span class="o">.</span><span class="n">_cache</span><span class="o">.</span><span class="n">datasets</span><span class="p">))</span>
<span class="bp">self</span><span class="o">.</span><span class="n">assertEqual</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">one</span><span class="o">.</span><span class="n">_cache</span><span class="o">.</span><span class="n">datasets</span><span class="o">.</span><span class="n">squeeze</span><span class="p">()</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">dataset</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">assertCountEqual</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">one</span><span class="o">.</span><span class="n">_cache</span><span class="o">.</span><span class="n">datasets</span><span class="o">.</span><span class="n">squeeze</span><span class="p">()</span><span class="o">.</span><span class="n">to_dict</span><span class="p">(),</span> <span class="n">dataset</span><span class="o">.</span><span class="n">to_dict</span><span class="p">())</span></div>


<div class="viewcode-block" id="TestONECache.test_save_loaded_ids">
Expand Down

0 comments on commit 7757f88

Please sign in to comment.