-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: support type conversions & metadata extranction via modules
- Loading branch information
Showing
28 changed files
with
1,889 additions
and
537 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"collapsed": true, | ||
"pycharm": { | ||
"name": "#%% md\n" | ||
} | ||
}, | ||
"source": [ | ||
"# Developing *kiara* modules\n", | ||
"\n", | ||
"This page will show you how to create your own *kiara* modules. It's early days still, so the way this is done\n", | ||
"currently is not as pythonic, user-friendly and easy as I hope it will eventually be. I do hope it is easy enough\n", | ||
"for everyone with a bit of Python experience to be able to create their own, simple modules, though.\n", | ||
"\n", | ||
"## (Optional) Create a project structure\n", | ||
"\n", | ||
"*kiara* modules live in Python packages. Although technically it would be possible to just use Python files,\n", | ||
"this is not supported for now, possibly ever. The main reason for that is that it is very important to be\n", | ||
"able to pinpoint the exact version of a module that was used to create/transform some data. Python packages\n", | ||
"can be versioned (as well as their dependencies) relatively easy, in a generic way. Simple scripts can't,\n", | ||
"at least not to the extend we need.\n", | ||
"\n", | ||
"Creating Python packages correctly is not trivial, which is why I created a [project template](https://github.com/DHARPA-Project/kiara_modules.project_template) that includes\n", | ||
"all the necessary bits and integrations to make this as painless as possible." | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 2 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython2", | ||
"version": "2.7.6" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"table": { | ||
"id": [ | ||
0, | ||
1 | ||
], | ||
"rel_path": [ | ||
"csv_1.csv", | ||
"csv_2.csv" | ||
], | ||
"file_name": [ | ||
"csv_1.csv", | ||
"csv_2.csv" | ||
], | ||
"content": [ | ||
"a,b,c\nd,e,f\n", | ||
"a,b,c\nd,e,f\n" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# -*- coding: utf-8 -*- | ||
import networkx | ||
import networkx as nx | ||
import typing | ||
from networkx import DiGraph | ||
|
||
from kiara.data.types import ValueType | ||
|
||
|
||
class NetworkGraphType(ValueType): | ||
def validate(cls, value: typing.Any) -> typing.Any: | ||
|
||
if not isinstance(value, networkx.Graph): | ||
raise ValueError(f"Invalid type '{type(value)}' for graph: {value}") | ||
return value | ||
|
||
def extract_type_metadata( | ||
cls, value: typing.Any | ||
) -> typing.Mapping[str, typing.Any]: | ||
|
||
graph: nx.Graph = value | ||
return { | ||
"directed": isinstance(value, DiGraph), | ||
"number_of_nodes": len(graph.nodes), | ||
"number_of_edges": len(graph.edges), | ||
"density": nx.density(graph), | ||
} |
Oops, something went wrong.