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

[pre-commit.ci] pre-commit autoupdate #6

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ exclude: '\\*.htm*'

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0 # the release, git tag, or commit you want to use
rev: v5.0.0 # the release, git tag, or commit you want to use
hooks:
- id: check-toml
- id: check-yaml
Expand All @@ -14,7 +14,7 @@ repos:

- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.4.5
rev: v0.9.4
hooks:
# Run the linter.
- id: ruff
Expand Down
78 changes: 54 additions & 24 deletions example/fruits.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,46 @@
"metadata": {},
"outputs": [],
"source": [
"fruits = {'plants': ['fruit', 'fruit', 'fruit', 'fruit', 'vegetable', 'vegetable', 'vegetable', 'vegetable'],\n",
" 'plts': ['fr', 'fr', 'fr', 'fr', 've', 've', 've', 've'], \n",
" 'quantity': ['1 kg', '10 kg', '1 kg', '10 kg', '1 kg', '10 kg', '1 kg', '10 kg'],\n",
" 'product': ['apple', 'apple', 'orange', 'orange', 'peppers', 'peppers', 'carrot', 'carrot'],\n",
" 'price': [1, 10, 2, 20, 1.5, 15, 1.5, 20],\n",
" 'price level': ['low', 'low', 'high', 'high', 'low', 'low', 'high', 'high'],\n",
" 'group': ['fruit 1', 'fruit 10', 'fruit 1', 'veget', 'veget', 'veget', 'veget', 'veget'],\n",
" 'id': [1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008],\n",
" 'supplier': [\"sup1\", \"sup1\", \"sup1\", \"sup2\", \"sup2\", \"sup2\", \"sup2\", \"sup1\"],\n",
" 'location': [\"fr\", \"gb\", \"es\", \"ch\", \"gb\", \"fr\", \"es\", \"ch\"],\n",
" 'valid': [\"ok\", \"ok\", \"ok\", \"ok\", \"ok\", \"ok\", \"ok\", \"ok\"]}"
"fruits = {\n",
" \"plants\": [\n",
" \"fruit\",\n",
" \"fruit\",\n",
" \"fruit\",\n",
" \"fruit\",\n",
" \"vegetable\",\n",
" \"vegetable\",\n",
" \"vegetable\",\n",
" \"vegetable\",\n",
" ],\n",
" \"plts\": [\"fr\", \"fr\", \"fr\", \"fr\", \"ve\", \"ve\", \"ve\", \"ve\"],\n",
" \"quantity\": [\"1 kg\", \"10 kg\", \"1 kg\", \"10 kg\", \"1 kg\", \"10 kg\", \"1 kg\", \"10 kg\"],\n",
" \"product\": [\n",
" \"apple\",\n",
" \"apple\",\n",
" \"orange\",\n",
" \"orange\",\n",
" \"peppers\",\n",
" \"peppers\",\n",
" \"carrot\",\n",
" \"carrot\",\n",
" ],\n",
" \"price\": [1, 10, 2, 20, 1.5, 15, 1.5, 20],\n",
" \"price level\": [\"low\", \"low\", \"high\", \"high\", \"low\", \"low\", \"high\", \"high\"],\n",
" \"group\": [\n",
" \"fruit 1\",\n",
" \"fruit 10\",\n",
" \"fruit 1\",\n",
" \"veget\",\n",
" \"veget\",\n",
" \"veget\",\n",
" \"veget\",\n",
" \"veget\",\n",
" ],\n",
" \"id\": [1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008],\n",
" \"supplier\": [\"sup1\", \"sup1\", \"sup1\", \"sup2\", \"sup2\", \"sup2\", \"sup2\", \"sup1\"],\n",
" \"location\": [\"fr\", \"gb\", \"es\", \"ch\", \"gb\", \"fr\", \"es\", \"ch\"],\n",
" \"valid\": [\"ok\", \"ok\", \"ok\", \"ok\", \"ok\", \"ok\", \"ok\", \"ok\"],\n",
"}"
]
},
{
Expand All @@ -57,6 +86,7 @@
"outputs": [],
"source": [
"from tab_dataset import Sdataset\n",
"\n",
"dts = Sdataset.ntv(fruits)\n",
"adts = dts.analysis"
]
Expand Down Expand Up @@ -90,9 +120,9 @@
}
],
"source": [
"print(adts.get_relation('plants', 'plts').typecoupl)\n",
"print(adts.get_relation('plants', 'product').typecoupl)\n",
"print(adts.get_relation('quantity', 'product').typecoupl)\n"
"print(adts.get_relation(\"plants\", \"plts\").typecoupl)\n",
"print(adts.get_relation(\"plants\", \"product\").typecoupl)\n",
"print(adts.get_relation(\"quantity\", \"product\").typecoupl)"
]
},
{
Expand Down Expand Up @@ -123,11 +153,11 @@
}
],
"source": [
"print('minimum distance: ', adts.get_relation('plants', 'plts').distance)\n",
"print('maximum distance: ', adts.get_relation('id', 'valid').distance)\n",
"print('intermediate distance: ', adts.get_relation('plants', 'product').distance)\n",
"# The 'plants' - 'product' relationship will be 'coupled' if we change, for example, \n",
"#'fruit-orange' in 'citrus-orange' and 'carrot-vegetable' in 'carrot-root vegetable' (2 changes) "
"print(\"minimum distance: \", adts.get_relation(\"plants\", \"plts\").distance)\n",
"print(\"maximum distance: \", adts.get_relation(\"id\", \"valid\").distance)\n",
"print(\"intermediate distance: \", adts.get_relation(\"plants\", \"product\").distance)\n",
"# The 'plants' - 'product' relationship will be 'coupled' if we change, for example,\n",
"#'fruit-orange' in 'citrus-orange' and 'carrot-vegetable' in 'carrot-root vegetable' (2 changes)"
]
},
{
Expand Down Expand Up @@ -238,7 +268,7 @@
}
],
"source": [
"adts.partitions(mode='id')"
"adts.partitions(mode=\"id\")"
]
},
{
Expand Down Expand Up @@ -304,7 +334,7 @@
}
],
"source": [
"adts.field_partition(mode='id')"
"adts.field_partition(mode=\"id\")"
]
},
{
Expand Down Expand Up @@ -362,7 +392,7 @@
}
],
"source": [
"adts.field_partition(mode='id', partition=['product', 'quantity'])"
"adts.field_partition(mode=\"id\", partition=[\"product\", \"quantity\"])"
]
},
{
Expand Down Expand Up @@ -393,7 +423,7 @@
}
],
"source": [
"adts.relation_partition(partition=['product', 'quantity'])"
"adts.relation_partition(partition=[\"product\", \"quantity\"])"
]
},
{
Expand Down Expand Up @@ -438,7 +468,7 @@
"metadata": {},
"outputs": [],
"source": [
"print(dts.to_xarray(idxname=['product', 'quantity']))"
"print(dts.to_xarray(idxname=[\"product\", \"quantity\"]))"
]
}
],
Expand Down
107 changes: 76 additions & 31 deletions example/fruits_df.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,46 @@
"metadata": {},
"outputs": [],
"source": [
"fruits = {'plants': ['fruit', 'fruit', 'fruit', 'fruit', 'vegetable', 'vegetable', 'vegetable', 'vegetable'],\n",
" 'plts': ['fr', 'fr', 'fr', 'fr', 've', 've', 've', 've'], \n",
" 'quantity': ['1 kg', '10 kg', '1 kg', '10 kg', '1 kg', '10 kg', '1 kg', '10 kg'],\n",
" 'product': ['apple', 'apple', 'orange', 'orange', 'peppers', 'peppers', 'carrot', 'carrot'],\n",
" 'price': [1, 10, 2, 20, 1.5, 15, 1.5, 20],\n",
" 'price level': ['low', 'low', 'high', 'high', 'low', 'low', 'high', 'high'],\n",
" 'group': ['fruit 1', 'fruit 10', 'fruit 1', 'veget', 'veget', 'veget', 'veget', 'veget'],\n",
" 'id': [1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008],\n",
" 'supplier': [\"sup1\", \"sup1\", \"sup1\", \"sup2\", \"sup2\", \"sup2\", \"sup2\", \"sup1\"],\n",
" 'location': [\"fr\", \"gb\", \"es\", \"ch\", \"gb\", \"fr\", \"es\", \"ch\"],\n",
" 'valid': [\"ok\", \"ok\", \"ok\", \"ok\", \"ok\", \"ok\", \"ok\", \"ok\"]}"
"fruits = {\n",
" \"plants\": [\n",
" \"fruit\",\n",
" \"fruit\",\n",
" \"fruit\",\n",
" \"fruit\",\n",
" \"vegetable\",\n",
" \"vegetable\",\n",
" \"vegetable\",\n",
" \"vegetable\",\n",
" ],\n",
" \"plts\": [\"fr\", \"fr\", \"fr\", \"fr\", \"ve\", \"ve\", \"ve\", \"ve\"],\n",
" \"quantity\": [\"1 kg\", \"10 kg\", \"1 kg\", \"10 kg\", \"1 kg\", \"10 kg\", \"1 kg\", \"10 kg\"],\n",
" \"product\": [\n",
" \"apple\",\n",
" \"apple\",\n",
" \"orange\",\n",
" \"orange\",\n",
" \"peppers\",\n",
" \"peppers\",\n",
" \"carrot\",\n",
" \"carrot\",\n",
" ],\n",
" \"price\": [1, 10, 2, 20, 1.5, 15, 1.5, 20],\n",
" \"price level\": [\"low\", \"low\", \"high\", \"high\", \"low\", \"low\", \"high\", \"high\"],\n",
" \"group\": [\n",
" \"fruit 1\",\n",
" \"fruit 10\",\n",
" \"fruit 1\",\n",
" \"veget\",\n",
" \"veget\",\n",
" \"veget\",\n",
" \"veget\",\n",
" \"veget\",\n",
" ],\n",
" \"id\": [1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008],\n",
" \"supplier\": [\"sup1\", \"sup1\", \"sup1\", \"sup2\", \"sup2\", \"sup2\", \"sup2\", \"sup1\"],\n",
" \"location\": [\"fr\", \"gb\", \"es\", \"ch\", \"gb\", \"fr\", \"es\", \"ch\"],\n",
" \"valid\": [\"ok\", \"ok\", \"ok\", \"ok\", \"ok\", \"ok\", \"ok\", \"ok\"],\n",
"}"
]
},
{
Expand All @@ -57,7 +86,6 @@
"outputs": [],
"source": [
"import pandas as pd\n",
"import ntv_pandas as npd\n",
"\n",
"df_fruits = pd.DataFrame(fruits)\n",
"ana_fruits = df_fruits.npd.analysis(distr=True)"
Expand Down Expand Up @@ -92,9 +120,9 @@
}
],
"source": [
"print(ana_fruits.get_relation('plants', 'plts').typecoupl)\n",
"print(ana_fruits.get_relation('plants', 'product').typecoupl)\n",
"print(ana_fruits.get_relation('quantity', 'product').typecoupl)\n"
"print(ana_fruits.get_relation(\"plants\", \"plts\").typecoupl)\n",
"print(ana_fruits.get_relation(\"plants\", \"product\").typecoupl)\n",
"print(ana_fruits.get_relation(\"quantity\", \"product\").typecoupl)"
]
},
{
Expand Down Expand Up @@ -125,11 +153,11 @@
}
],
"source": [
"print('minimum distance: ', ana_fruits.get_relation('plants', 'plts').distance)\n",
"print('maximum distance: ', ana_fruits.get_relation('id', 'valid').distance)\n",
"print('intermediate distance: ', ana_fruits.get_relation('plants', 'product').distance)\n",
"# The 'plants' - 'product' relationship will be 'coupled' if we change, for example, \n",
"#'fruit-orange' in 'citrus-orange' and 'carrot-vegetable' in 'carrot-root vegetable' (2 changes) "
"print(\"minimum distance: \", ana_fruits.get_relation(\"plants\", \"plts\").distance)\n",
"print(\"maximum distance: \", ana_fruits.get_relation(\"id\", \"valid\").distance)\n",
"print(\"intermediate distance: \", ana_fruits.get_relation(\"plants\", \"product\").distance)\n",
"# The 'plants' - 'product' relationship will be 'coupled' if we change, for example,\n",
"#'fruit-orange' in 'citrus-orange' and 'carrot-vegetable' in 'carrot-root vegetable' (2 changes)"
]
},
{
Expand Down Expand Up @@ -164,7 +192,12 @@
],
"source": [
"# list of categories for each Field\n",
"print({field.idfield: category for field, category in zip(ana_fruits.fields, ana_fruits.category)})"
"print(\n",
" {\n",
" field.idfield: category\n",
" for field, category in zip(ana_fruits.fields, ana_fruits.category)\n",
" }\n",
")"
]
},
{
Expand Down Expand Up @@ -240,7 +273,7 @@
}
],
"source": [
"ana_fruits.partitions(mode='id')"
"ana_fruits.partitions(mode=\"id\")"
]
},
{
Expand Down Expand Up @@ -306,7 +339,7 @@
}
],
"source": [
"ana_fruits.field_partition() #first partition"
"ana_fruits.field_partition() # first partition"
]
},
{
Expand Down Expand Up @@ -364,7 +397,7 @@
}
],
"source": [
"ana_fruits.field_partition(partition=['product', 'quantity'])"
"ana_fruits.field_partition(partition=[\"product\", \"quantity\"])"
]
},
{
Expand Down Expand Up @@ -395,7 +428,7 @@
}
],
"source": [
"ana_fruits.relation_partition(partition=['product', 'quantity'])"
"ana_fruits.relation_partition(partition=[\"product\", \"quantity\"])"
]
},
{
Expand Down Expand Up @@ -433,7 +466,15 @@
"source": [
"from base64 import b64encode\n",
"from IPython.display import Image, display\n",
"display(Image(url=\"https://mermaid.ink/img/\" + b64encode(open('fruits.mmd', 'r', encoding=\"utf-8\").read().encode(\"ascii\")).decode(\"ascii\")))"
"\n",
"display(\n",
" Image(\n",
" url=\"https://mermaid.ink/img/\"\n",
" + b64encode(\n",
" open(\"fruits.mmd\", \"r\", encoding=\"utf-8\").read().encode(\"ascii\")\n",
" ).decode(\"ascii\")\n",
" )\n",
")"
]
},
{
Expand Down Expand Up @@ -871,7 +912,7 @@
"source": [
"from ntv_numpy import Xdataset\n",
"\n",
"xd_fruits = Xdataset.from_dataframe(df_fruits) # Xdataset is a neutral format\n",
"xd_fruits = Xdataset.from_dataframe(df_fruits) # Xdataset is a neutral format\n",
"xd_fruits.to_xarray(json_name=False)"
]
},
Expand All @@ -884,8 +925,12 @@
"source": [
"df2_fruits = xd_fruits.to_dataframe(json_name=False).reset_index()\n",
"\n",
"df_fruits_sort = df_fruits.sort_values(ana_fruits.partitions()[0]).reset_index(drop=True)\n",
"df2_fruits_sort = df2_fruits.sort_values(ana_fruits.partitions()[0]).reset_index(drop=True)[df_fruits.columns]"
"df_fruits_sort = df_fruits.sort_values(ana_fruits.partitions()[0]).reset_index(\n",
" drop=True\n",
")\n",
"df2_fruits_sort = df2_fruits.sort_values(ana_fruits.partitions()[0]).reset_index(\n",
" drop=True\n",
")[df_fruits.columns]"
]
},
{
Expand Down Expand Up @@ -1342,8 +1387,8 @@
}
],
"source": [
"xd_fruits_other = Xdataset.from_dataframe(df_fruits, dims=['product', 'quantity'])\n",
"xd_fruits_other.to_xarray(idxname=['product', 'quantity'])"
"xd_fruits_other = Xdataset.from_dataframe(df_fruits, dims=[\"product\", \"quantity\"])\n",
"xd_fruits_other.to_xarray(idxname=[\"product\", \"quantity\"])"
]
}
],
Expand Down
Loading