Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Sep 2, 2024
1 parent 8f55926 commit ee1067e
Show file tree
Hide file tree
Showing 10 changed files with 1,034 additions and 570 deletions.
102 changes: 63 additions & 39 deletions example/example_analysis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -72,28 +72,33 @@
}
],
"source": [
"# Json data model \n",
"df_country = { \n",
" 'country and region:$erDiagram' : { \n",
" 'entity': {\n",
" 'COUNTRY': [ \n",
" ['string', 'country', 'PK' ], \n",
" ['string', 'code', 'unique'] \n",
" ], \n",
" 'REGION': [ \n",
" ['string', 'region', 'PK'],\n",
" ['number', 'population'] \n",
" ]\n",
"# Json data model\n",
"df_country = {\n",
" \"country and region:$erDiagram\": {\n",
" \"entity\": {\n",
" \"COUNTRY\": [[\"string\", \"country\", \"PK\"], [\"string\", \"code\", \"unique\"]],\n",
" \"REGION\": [[\"string\", \"region\", \"PK\"], [\"number\", \"population\"]],\n",
" },\n",
" 'relationship': [ \n",
" [ 'REGION', 'exactly one', 'identifying', 'one or more', 'COUNTRY', 'brings_together']\n",
" \"relationship\": [\n",
" [\n",
" \"REGION\",\n",
" \"exactly one\",\n",
" \"identifying\",\n",
" \"one or more\",\n",
" \"COUNTRY\",\n",
" \"brings_together\",\n",
" ]\n",
" ],\n",
"\n",
" } }\n",
" }\n",
"}\n",
"\n",
"# It is converted in Mermaid structure and then displayed\n",
"diag = MermaidConnec.diagram(df_country)\n",
"display(Image(url=\"https://mermaid.ink/img/\" + b64encode(diag.encode(\"ascii\")).decode(\"ascii\")))"
"display(\n",
" Image(\n",
" url=\"https://mermaid.ink/img/\" + b64encode(diag.encode(\"ascii\")).decode(\"ascii\")\n",
" )\n",
")"
]
},
{
Expand Down Expand Up @@ -176,8 +181,7 @@
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import ntv_pandas as npd"
"import pandas as pd"
]
},
{
Expand All @@ -187,10 +191,12 @@
"metadata": {},
"outputs": [],
"source": [
"example1 = {'country' : ['France', 'Spain', 'Estonia', 'Nigeria'],\n",
" 'region': ['European Union', 'European Union', 'European Union', 'Africa'],\n",
" 'code': ['FR', 'ES', 'ES', 'NI'],\n",
" 'population': [449, 48, 449, 1460]}\n",
"example1 = {\n",
" \"country\": [\"France\", \"Spain\", \"Estonia\", \"Nigeria\"],\n",
" \"region\": [\"European Union\", \"European Union\", \"European Union\", \"Africa\"],\n",
" \"code\": [\"FR\", \"ES\", \"ES\", \"NI\"],\n",
" \"population\": [449, 48, 449, 1460],\n",
"}\n",
"pd_ex1 = pd.DataFrame(example1)"
]
},
Expand Down Expand Up @@ -222,11 +228,19 @@
],
"source": [
"ana1 = pd_ex1.npd.analysis()\n",
"print(\"country - code (must be coupled): \", ana1.get_relation('country', 'code').typecoupl)\n",
"print(\"region - population (must be derived True): \", ana1.get_relation('region', 'population').typecoupl, \n",
" ana1.get_relation('region', 'population').parent_child)\n",
"print(\"country - region (must be derived True): \", ana1.get_relation('country', 'region').typecoupl,\n",
" ana1.get_relation('country', 'region').parent_child)"
"print(\n",
" \"country - code (must be coupled): \", ana1.get_relation(\"country\", \"code\").typecoupl\n",
")\n",
"print(\n",
" \"region - population (must be derived True): \",\n",
" ana1.get_relation(\"region\", \"population\").typecoupl,\n",
" ana1.get_relation(\"region\", \"population\").parent_child,\n",
")\n",
"print(\n",
" \"country - region (must be derived True): \",\n",
" ana1.get_relation(\"country\", \"region\").typecoupl,\n",
" ana1.get_relation(\"country\", \"region\").parent_child,\n",
")"
]
},
{
Expand All @@ -253,8 +267,8 @@
}
],
"source": [
"print(pd_ex1.npd.check_relation('country', 'code', 'coupled', value=True))\n",
"print(pd_ex1.npd.check_relation('region', 'population', 'derived', value=True))"
"print(pd_ex1.npd.check_relation(\"country\", \"code\", \"coupled\", value=True))\n",
"print(pd_ex1.npd.check_relation(\"region\", \"population\", \"derived\", value=True))"
]
},
{
Expand Down Expand Up @@ -294,10 +308,12 @@
"metadata": {},
"outputs": [],
"source": [
"example2 = {'country' : ['France', 'Spain', 'Estonia', 'Nigeria'],\n",
" 'region': ['European Union', 'European Union', 'European Union', 'Africa'],\n",
" 'code': ['FR', 'ES', 'EE', 'NI'],\n",
" 'population': [449, 449, 449, 1460]}\n",
"example2 = {\n",
" \"country\": [\"France\", \"Spain\", \"Estonia\", \"Nigeria\"],\n",
" \"region\": [\"European Union\", \"European Union\", \"European Union\", \"Africa\"],\n",
" \"code\": [\"FR\", \"ES\", \"EE\", \"NI\"],\n",
" \"population\": [449, 449, 449, 1460],\n",
"}\n",
"pd_ex2 = pd.DataFrame(example2)"
]
},
Expand All @@ -321,11 +337,19 @@
],
"source": [
"ana2 = pd_ex2.npd.analysis()\n",
"print(\"country - code (must be coupled): \", ana2.get_relation('country', 'code').typecoupl)\n",
"print(\"region - population (must be derived True): \", ana2.get_relation('region', 'population').typecoupl, \n",
" ana2.get_relation('region', 'population').parent_child)\n",
"print(\"country - region (must be derived True): \", ana2.get_relation('country', 'region').typecoupl,\n",
" ana2.get_relation('country', 'region').parent_child)"
"print(\n",
" \"country - code (must be coupled): \", ana2.get_relation(\"country\", \"code\").typecoupl\n",
")\n",
"print(\n",
" \"region - population (must be derived True): \",\n",
" ana2.get_relation(\"region\", \"population\").typecoupl,\n",
" ana2.get_relation(\"region\", \"population\").parent_child,\n",
")\n",
"print(\n",
" \"country - region (must be derived True): \",\n",
" ana2.get_relation(\"country\", \"region\").typecoupl,\n",
" ana2.get_relation(\"country\", \"region\").parent_child,\n",
")"
]
},
{
Expand Down
Loading

0 comments on commit ee1067e

Please sign in to comment.