cai-causal-graph 0.5.2__tar.gz → 0.5.4.dev0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {cai_causal_graph-0.5.2 → cai_causal_graph-0.5.4.dev0}/PKG-INFO +1 -1
- {cai_causal_graph-0.5.2 → cai_causal_graph-0.5.4.dev0}/cai_causal_graph/__init__.py +1 -1
- {cai_causal_graph-0.5.2 → cai_causal_graph-0.5.4.dev0}/cai_causal_graph/causal_graph.py +20 -17
- {cai_causal_graph-0.5.2 → cai_causal_graph-0.5.4.dev0}/cai_causal_graph/utils.py +11 -1
- {cai_causal_graph-0.5.2 → cai_causal_graph-0.5.4.dev0}/pyproject.toml +1 -1
- {cai_causal_graph-0.5.2 → cai_causal_graph-0.5.4.dev0}/LICENSE +0 -0
- {cai_causal_graph-0.5.2 → cai_causal_graph-0.5.4.dev0}/README.md +0 -0
- {cai_causal_graph-0.5.2 → cai_causal_graph-0.5.4.dev0}/cai_causal_graph/exceptions.py +0 -0
- {cai_causal_graph-0.5.2 → cai_causal_graph-0.5.4.dev0}/cai_causal_graph/graph_components.py +0 -0
- {cai_causal_graph-0.5.2 → cai_causal_graph-0.5.4.dev0}/cai_causal_graph/identify_utils.py +0 -0
- {cai_causal_graph-0.5.2 → cai_causal_graph-0.5.4.dev0}/cai_causal_graph/interfaces.py +0 -0
- {cai_causal_graph-0.5.2 → cai_causal_graph-0.5.4.dev0}/cai_causal_graph/metadata_handler.py +0 -0
- {cai_causal_graph-0.5.2 → cai_causal_graph-0.5.4.dev0}/cai_causal_graph/time_series_causal_graph.py +0 -0
- {cai_causal_graph-0.5.2 → cai_causal_graph-0.5.4.dev0}/cai_causal_graph/type_definitions.py +0 -0
|
@@ -16,6 +16,7 @@ limitations under the License.
|
|
|
16
16
|
from __future__ import annotations
|
|
17
17
|
|
|
18
18
|
import itertools
|
|
19
|
+
import warnings
|
|
19
20
|
from collections import defaultdict
|
|
20
21
|
from copy import deepcopy
|
|
21
22
|
from functools import wraps
|
|
@@ -433,23 +434,7 @@ class CausalGraph(HasIdentifier, HasMetadata, CanDictSerialize, CanDictDeseriali
|
|
|
433
434
|
>>> # add an undirected edge between 'input1' and 'input2'
|
|
434
435
|
>>> causal_graph.add_edge('input1', 'input2', edge_type=EdgeType.UNDIRECTED_EDGE)
|
|
435
436
|
|
|
436
|
-
|
|
437
|
-
construction, automatically creates a fully-connected bipartite directed causal graph. This means that all
|
|
438
|
-
inputs are automatically connected to all outputs by means of directed edges. But there will be no edges
|
|
439
|
-
between inputs and no edges between outputs; this will be a simple two layer graph. For example,
|
|
440
|
-
|
|
441
|
-
>>> from cai_causal_graph import CausalGraph
|
|
442
|
-
>>>
|
|
443
|
-
>>> input_list = ['input1', 'input2']
|
|
444
|
-
>>> output_list = ['output1', 'output2']
|
|
445
|
-
>>>
|
|
446
|
-
>>> # Create a fully connected graph from inputs to outputs
|
|
447
|
-
>>> causal_graph = CausalGraph(
|
|
448
|
-
>>> input_list=input_list,
|
|
449
|
-
>>> output_list=output_list,
|
|
450
|
-
>>> )
|
|
451
|
-
|
|
452
|
-
Finally, it is straightforward to export an instantiated `cai_causal_graph.causal_graph.CausalGraph` to a
|
|
437
|
+
It is straightforward to export an instantiated `cai_causal_graph.causal_graph.CausalGraph` to a
|
|
453
438
|
serializable dictionary,
|
|
454
439
|
|
|
455
440
|
>>> causal_graph_dict = causal_graph.to_dict()
|
|
@@ -473,12 +458,30 @@ class CausalGraph(HasIdentifier, HasMetadata, CanDictSerialize, CanDictDeseriali
|
|
|
473
458
|
|
|
474
459
|
# Add nodes.
|
|
475
460
|
if input_list is not None:
|
|
461
|
+
warnings.warn(
|
|
462
|
+
'Passing input_list during construction of a CausalGraph is now deprecated, and will be '
|
|
463
|
+
'removed in future versions. To maintain this behavior, call add_fully_connected_nodes after '
|
|
464
|
+
'construction.',
|
|
465
|
+
category=DeprecationWarning,
|
|
466
|
+
)
|
|
476
467
|
self.add_nodes_from(input_list)
|
|
477
468
|
if output_list is not None:
|
|
469
|
+
warnings.warn(
|
|
470
|
+
'Passing output_list during construction of a CausalGraph is now deprecated, and will be '
|
|
471
|
+
'removed in future versions. To maintain this behavior, call add_fully_connected_nodes after '
|
|
472
|
+
'construction.',
|
|
473
|
+
category=DeprecationWarning,
|
|
474
|
+
)
|
|
478
475
|
self.add_nodes_from(output_list)
|
|
479
476
|
|
|
480
477
|
# create a fully-connected causal graph if specified, using only directed edges
|
|
481
478
|
if fully_connected and input_list is not None and output_list is not None:
|
|
479
|
+
warnings.warn(
|
|
480
|
+
'Passing fully_connected during construction of a CausalGraph is now deprecated, and will be '
|
|
481
|
+
'removed in future versions. To maintain this behavior, call add_fully_connected_nodes after '
|
|
482
|
+
'construction.',
|
|
483
|
+
category=DeprecationWarning,
|
|
484
|
+
)
|
|
482
485
|
self.add_fully_connected_nodes(input_list, output_list)
|
|
483
486
|
# No else needed as no edges need to be added.
|
|
484
487
|
|
|
@@ -44,7 +44,17 @@ def get_variable_name_and_lag(node_name: NodeLike) -> Tuple[str, int]:
|
|
|
44
44
|
if not isinstance(node_name, str):
|
|
45
45
|
raise TypeError(f'Expected node name to be a string, got type {type(node_name)}.')
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
# This matches three groups:
|
|
48
|
+
# (?s:(.+?\n?)) - The variable name. The main bulk of it - (?s:(.+?)) - matches any characters (including new lines)
|
|
49
|
+
# in a non-greedy fashion, meaning it won't capture ' lag(n=X)' or ' future(n=X)' at the end as part of the
|
|
50
|
+
# variable, as they will be captured by the other matching groups. The extra \n* in the group is there because
|
|
51
|
+
# for some reason the main bulk fails to match trailing new lines if there is no lag or future afterward. Not
|
|
52
|
+
# sure why, but this fixes it.
|
|
53
|
+
# (?: lag\(n=(\d+)\))? - Optionally the lag in the past. This matches the whole 'lag(n=X)' section, but the captured
|
|
54
|
+
# group is only the lag value.
|
|
55
|
+
# (?: future\(n=(\d+)\))? - Optionally the lag in the future. This matches the whole 'future(n=X)' section, but the
|
|
56
|
+
# captured group is only the future lag value.
|
|
57
|
+
is_match = re.match(r'^(?s:(.+?\n*))(?: lag\(n=(\d+)\))?(?: future\(n=(\d+)\))?$', node_name)
|
|
48
58
|
|
|
49
59
|
lag_matches = re.findall(r'lag\(n=(\d+)\)', node_name)
|
|
50
60
|
future_matches = re.findall(r'future\(n=(\d+)\)', node_name)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cai_causal_graph-0.5.2 → cai_causal_graph-0.5.4.dev0}/cai_causal_graph/time_series_causal_graph.py
RENAMED
|
File without changes
|
|
File without changes
|