From 9e859ab6c1d889c50bfe641472e9dc4c2ed5faeb Mon Sep 17 00:00:00 2001 From: Omen Apps Date: Fri, 26 Feb 2021 10:38:27 -0500 Subject: [PATCH] NetworkX and Pandas are optional dependencies for experimental tools --- README.md | 9 ++++++++- django_postgresql_dag/transformations.py | 14 +++++++++----- setup.py | 3 +++ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 63927d1..9c7c61c 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,14 @@ Currently, it provides numerous methods for retrieving nodes, and a few for retr [Quickstart example](https://django-postgresql-dag.readthedocs.io/en/latest/quickstart.html) +## Install + + pip install django-postgresql-dag + +With optional dependencies for using transformations: + + pip install django-postgresql-dag[transforms] + ## ToDo @@ -29,4 +37,3 @@ Currently, it provides numerous methods for retrieving nodes, and a few for retr 2. [django-dag](https://pypi.org/project/django-dag/) 3. [django-dag-postgresql](https://github.com/worsht/django-dag-postgresql) 4. [django-treebeard-dag](https://pypi.org/project/django-treebeard-dag/) - diff --git a/django_postgresql_dag/transformations.py b/django_postgresql_dag/transformations.py index b11ada7..d14e79d 100644 --- a/django_postgresql_dag/transformations.py +++ b/django_postgresql_dag/transformations.py @@ -3,16 +3,18 @@ django-postgresql-dag to alternate formats. """ +from itertools import chain + +import networkx as nx +import pandas as pd from django.core.exceptions import FieldDoesNotExist from django.db.models import Case, When from django.db.models.fields import DateTimeField, UUIDField -from django.db.models.fields.files import ImageField, FileField +from django.db.models.fields.files import FileField, ImageField from django.db.models.fields.related import ManyToManyField -from .exceptions import GraphModelsCannotBeParsedException, IncorrectUsageException - -from itertools import chain -import networkx as nx +from .exceptions import (GraphModelsCannotBeParsedException, + IncorrectUsageException) def _ordered_filter(queryset, field_names, values): @@ -203,6 +205,8 @@ def nx_from_queryset( graph_attributes_dict: A dictionary of attributes to add to the graph itself node_attribute_fields_list: a list of strings of field names to be added to nodes edge_attribute_fields_list: a list of strings of field names to be added to edges + date_strf: if any provided fields are date-like, how should they be formatted? + digraph: bool to determine whether to output a directed or undirected graph """ _NodeModel, _EdgeModel, queryset_type = get_queryset_characteristics(queryset) diff --git a/setup.py b/setup.py index 9e4f606..1cad1c1 100644 --- a/setup.py +++ b/setup.py @@ -45,4 +45,7 @@ classifiers=classifiers, long_description_content_type="text/markdown", long_description=long_desc, + extras_require = { + 'transforms': ['networkx>=2.5', 'pandas>=1.2'] + } )