Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix load_bulk_data #13

Merged
merged 3 commits into from
Jan 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
164 changes: 47 additions & 117 deletions nbs/05_pheno_loader.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,17 @@
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {
"vscode": {
"languageId": "python"
}
},
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#| default_exp pheno_loader"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {
"vscode": {
"languageId": "python"
}
},
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#| hide\n",
Expand All @@ -41,12 +33,8 @@
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {
"vscode": {
"languageId": "python"
}
},
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#| export\n",
Expand All @@ -65,12 +53,8 @@
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {
"vscode": {
"languageId": "python"
}
},
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#| export\n",
Expand All @@ -92,12 +76,8 @@
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {
"vscode": {
"languageId": "python"
}
},
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#| export\n",
Expand Down Expand Up @@ -692,6 +672,8 @@
" \"\"\"\n",
" # Identify common index levels\n",
" common_index_levels = list(set(data.index.names).intersection(set(more_levels.index.names)))\n",
" if len(common_index_levels) == 0:\n",
" return data\n",
" \n",
" # Identify the extra index level in more_levels\n",
" extra_index_levels = [l for l in more_levels.index.names if l not in common_index_levels]\n",
Expand Down Expand Up @@ -805,12 +787,8 @@
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {
"vscode": {
"languageId": "python"
}
},
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
Expand All @@ -820,7 +798,7 @@
"2 tables: ['fundus', 'age_sex']"
]
},
"execution_count": 30,
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -848,12 +826,8 @@
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {
"vscode": {
"languageId": "python"
}
},
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
Expand Down Expand Up @@ -992,7 +966,7 @@
"collection_date 2021-02-17 datetime64[ns] "
]
},
"execution_count": 31,
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -1003,20 +977,16 @@
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {
"vscode": {
"languageId": "python"
}
},
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"dict_keys(['fundus', 'age_sex'])"
]
},
"execution_count": 32,
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -1027,12 +997,8 @@
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {
"vscode": {
"languageId": "python"
}
},
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
Expand Down Expand Up @@ -1325,7 +1291,7 @@
"[3 rows x 76 columns]"
]
},
"execution_count": 33,
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -1344,12 +1310,8 @@
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {
"vscode": {
"languageId": "python"
}
},
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
Expand All @@ -1361,7 +1323,7 @@
" 'artery_fractal_dimension_left']"
]
},
"execution_count": 34,
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -1380,12 +1342,8 @@
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {
"vscode": {
"languageId": "python"
}
},
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
Expand Down Expand Up @@ -1508,7 +1466,7 @@
"4 10k 00_00_visit 0 50.3 0 "
]
},
"execution_count": 35,
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -1527,12 +1485,8 @@
},
{
"cell_type": "code",
"execution_count": 36,
"metadata": {
"vscode": {
"languageId": "python"
}
},
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
Expand All @@ -1546,7 +1500,7 @@
"Name: fundus_image_left, dtype: object"
]
},
"execution_count": 36,
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -1557,12 +1511,8 @@
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {
"vscode": {
"languageId": "python"
}
},
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#| hide\n",
Expand All @@ -1572,20 +1522,16 @@
},
{
"cell_type": "code",
"execution_count": 38,
"metadata": {
"vscode": {
"languageId": "python"
}
},
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[None, None]"
]
},
"execution_count": 38,
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
},
Expand Down Expand Up @@ -1624,12 +1570,8 @@
},
{
"cell_type": "code",
"execution_count": 39,
"metadata": {
"vscode": {
"languageId": "python"
}
},
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"pl = PhenoLoader('fundus', flexible_field_search=True)"
Expand All @@ -1645,12 +1587,8 @@
},
{
"cell_type": "code",
"execution_count": 40,
"metadata": {
"vscode": {
"languageId": "python"
}
},
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
Expand Down Expand Up @@ -1751,7 +1689,7 @@
"4 10k 00_00_visit 0 1.557029 "
]
},
"execution_count": 40,
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -1770,12 +1708,8 @@
},
{
"cell_type": "code",
"execution_count": 41,
"metadata": {
"vscode": {
"languageId": "python"
}
},
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
Expand Down Expand Up @@ -1947,12 +1881,8 @@
},
{
"cell_type": "code",
"execution_count": 42,
"metadata": {
"vscode": {
"languageId": "python"
}
},
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#| hide\n",
Expand Down
10 changes: 5 additions & 5 deletions nbs/14_bulk_data_loader.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"outputs": [],
"source": [
"#| export\n",
"FIELD_TYPE_TO_FUNC = pd.read_csv(DICT_PROPERTY_PATH, index_col='field_type').to_dict()['load_func']"
"FIELD_TYPE_TO_FUNC = pd.read_csv(DICT_PROPERTY_PATH, index_col='field_type')['load_func'].dropna().to_dict()"
]
},
{
Expand All @@ -78,10 +78,10 @@
"#| export\n",
"def get_function_for_field_type(field_type):\n",
" function_name = FIELD_TYPE_TO_FUNC.get(field_type, \"read_parquet\")\n",
" try:\n",
" return globals().get(function_name)\n",
" except:\n",
" raise ValueError(f\"Function {function_name} not found\")\n"
" load_func = globals().get(function_name)\n",
" if load_func is None:\n",
" raise ValueError(f\"Function {function_name} not found\")\n",
" return load_func\n"
]
},
{
Expand Down
Loading