Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
velochy committed May 20, 2024
1 parent f7d3841 commit 2687a41
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
6 changes: 3 additions & 3 deletions nbs/01_io.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@
"\n",
"# Take a list and a dict and replace all dict keys in list with their corresponding lists in-place\n",
"def list_aliases(lst, da):\n",
" return [ fv for v in lst for fv in (da[v] if v in da else [v]) ]"
" return [ fv for v in lst for fv in (da[v] if isinstance(v,str) and v in da else [v]) ]"
]
},
{
Expand Down Expand Up @@ -597,7 +597,7 @@
"outputs": [],
"source": [
"#| export\n",
"def read_and_process_data(desc, return_meta=False, constants={}):\n",
"def read_and_process_data(desc, return_meta=False, constants={}, skip_postprocessing=False):\n",
"\n",
" df, meta = read_concatenate_files_list(desc)\n",
"\n",
Expand All @@ -608,7 +608,7 @@
" globs = {'pd':pd, 'np':np, 'stk':stk, 'df':df, **constants}\n",
" if 'preprocessing' in desc: exec(desc['preprocessing'], globs)\n",
" if 'filter' in desc: globs['df'] = globs['df'][eval(desc['filter'], globs)]\n",
" if 'postprocessing' in desc: exec(desc['postprocessing'],globs)\n",
" if 'postprocessing' in desc and not skip_post: exec(desc['postprocessing'],globs)\n",
" df = globs['df']\n",
" \n",
" return (df, meta) if return_meta else df"
Expand Down
9 changes: 7 additions & 2 deletions nbs/02_pp.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,9 @@
" #print( [ data[(data[factor_cols]==c).all(axis=1)] for c in combs ] )\n",
" #print(list(combs))\n",
" return list(batch([\n",
" alt_wrapper(plot_fn(data[(data[factor_cols]==c).all(axis=1)],**pparams).properties(title='-'.join(map(str,c)),**dims, **alt_properties))\n",
" alt_wrapper(plot_fn(data[(data[factor_cols]==c).all(axis=1)],**pparams)\n",
" .properties(title='-'.join(map(str,c)),**dims, **alt_properties)\n",
" .configure_view(discreteHeight={'step':20}))\n",
" for c in combs\n",
" ], n_facet_cols))\n",
" else: # Use faceting\n",
Expand All @@ -873,8 +875,11 @@
" row=alt.Row(f'{factor_cols[0]}:O', sort=list(data[factor_cols[0]].dtype.categories), header=alt.Header(labelOrient='top'))))\n",
" else: # n_facet_cols!=1 but just one facet\n",
" plot = alt_wrapper(plot_fn(**pparams).properties(**dims, **alt_properties).facet(f'{factor_cols[0]}:O',columns=n_facet_cols))\n",
" plot = plot.configure_view(discreteHeight={'step':20})\n",
" else:\n",
" plot = alt_wrapper(plot_fn(**pparams).properties(**dims, **alt_properties))\n",
" plot = alt_wrapper(plot_fn(**pparams).properties(**dims, **alt_properties)\n",
" .configure_view(discreteHeight={'step':20}))\n",
"\n",
" if return_matrix_of_plots: plot = [[plot]]\n",
"\n",
" return plot\n"
Expand Down
6 changes: 3 additions & 3 deletions salk_toolkit/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def group_columns_dict(data_meta):

# Take a list and a dict and replace all dict keys in list with their corresponding lists in-place
def list_aliases(lst, da):
return [ fv for v in lst for fv in (da[v] if v in da else [v]) ]
return [ fv for v in lst for fv in (da[v] if isinstance(v,str) and v in da else [v]) ]

# %% ../nbs/01_io.ipynb 10
# Creates a mapping old -> new
Expand Down Expand Up @@ -475,7 +475,7 @@ def data_with_inferred_meta(data_file, **kwargs):


# %% ../nbs/01_io.ipynb 15
def read_and_process_data(desc, return_meta=False, constants={}):
def read_and_process_data(desc, return_meta=False, constants={}, skip_postprocessing=False):

df, meta = read_concatenate_files_list(desc)

Expand All @@ -486,7 +486,7 @@ def read_and_process_data(desc, return_meta=False, constants={}):
globs = {'pd':pd, 'np':np, 'stk':stk, 'df':df, **constants}
if 'preprocessing' in desc: exec(desc['preprocessing'], globs)
if 'filter' in desc: globs['df'] = globs['df'][eval(desc['filter'], globs)]
if 'postprocessing' in desc: exec(desc['postprocessing'],globs)
if 'postprocessing' in desc and not skip_post: exec(desc['postprocessing'],globs)
df = globs['df']

return (df, meta) if return_meta else df
Expand Down
8 changes: 6 additions & 2 deletions salk_toolkit/pp.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,9 @@ def create_plot(pparams, data_meta, pp_desc, alt_properties={}, alt_wrapper=None
#print( [ data[(data[factor_cols]==c).all(axis=1)] for c in combs ] )
#print(list(combs))
return list(batch([
alt_wrapper(plot_fn(data[(data[factor_cols]==c).all(axis=1)],**pparams).properties(title='-'.join(map(str,c)),**dims, **alt_properties))
alt_wrapper(plot_fn(data[(data[factor_cols]==c).all(axis=1)],**pparams)
.properties(title='-'.join(map(str,c)),**dims, **alt_properties)
.configure_view(discreteHeight={'step':20}))
for c in combs
], n_facet_cols))
else: # Use faceting
Expand All @@ -634,8 +636,10 @@ def create_plot(pparams, data_meta, pp_desc, alt_properties={}, alt_wrapper=None
row=alt.Row(f'{factor_cols[0]}:O', sort=list(data[factor_cols[0]].dtype.categories), header=alt.Header(labelOrient='top'))))
else: # n_facet_cols!=1 but just one facet
plot = alt_wrapper(plot_fn(**pparams).properties(**dims, **alt_properties).facet(f'{factor_cols[0]}:O',columns=n_facet_cols))
plot = plot.configure_view(discreteHeight={'step':20})
else:
plot = alt_wrapper(plot_fn(**pparams).properties(**dims, **alt_properties))
plot = alt_wrapper(plot_fn(**pparams).properties(**dims, **alt_properties).configure_view(discreteHeight={'step':20}))

if return_matrix_of_plots: plot = [[plot]]

return plot
Expand Down

0 comments on commit 2687a41

Please sign in to comment.