mirror of
https://github.com/qurator-spk/modstool.git
synced 2025-06-08 11:20:07 +02:00
🧹 Remove unused/obsolete code
This commit is contained in:
parent
39f7d8646a
commit
6af4a6f671
2 changed files with 1 additions and 31 deletions
|
@ -301,36 +301,6 @@ def flatten(d: MutableMapping, parent='', separator='_'):
|
||||||
return dict(items)
|
return dict(items)
|
||||||
|
|
||||||
|
|
||||||
def dicts_to_df(data_list: List[Dict], *, index_column) -> pd.DataFrame:
|
|
||||||
"""
|
|
||||||
Convert the given list of dicts to a Pandas DataFrame.
|
|
||||||
|
|
||||||
The keys of the dicts make the columns.
|
|
||||||
"""
|
|
||||||
|
|
||||||
# Build columns from keys
|
|
||||||
columns = []
|
|
||||||
for m in data_list:
|
|
||||||
for c in m.keys():
|
|
||||||
if c not in columns:
|
|
||||||
columns.append(c)
|
|
||||||
|
|
||||||
# Build data table
|
|
||||||
data = [[m.get(c) for c in columns] for m in data_list]
|
|
||||||
|
|
||||||
# Build index
|
|
||||||
if isinstance(index_column, str):
|
|
||||||
index = [m[index_column] for m in data_list]
|
|
||||||
elif isinstance(index_column, tuple):
|
|
||||||
index = [[m[c] for m in data_list] for c in index_column]
|
|
||||||
index = pd.MultiIndex.from_arrays(index, names=index_column)
|
|
||||||
else:
|
|
||||||
raise ValueError(f"index_column must")
|
|
||||||
|
|
||||||
df = pd.DataFrame(data=data, index=index, columns=columns)
|
|
||||||
return df
|
|
||||||
|
|
||||||
|
|
||||||
def valid_column_key(k):
|
def valid_column_key(k):
|
||||||
if re.match("^[a-zA-Z0-9 _@/:\[\]-]+$", k):
|
if re.match("^[a-zA-Z0-9 _@/:\[\]-]+$", k):
|
||||||
return True
|
return True
|
||||||
|
|
|
@ -18,7 +18,7 @@ import click
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
|
|
||||||
from .lib import sorted_groupby, TagGroup, ns, flatten, dicts_to_df, insert_into_db, insert_into_db_multiple
|
from .lib import sorted_groupby, TagGroup, ns, flatten, insert_into_db, insert_into_db_multiple
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue