tracepipe 0.3.3__py3-none-any.whl → 0.3.5__py3-none-any.whl
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.
- tracepipe/__init__.py +1 -1
- tracepipe/context.py +4 -0
- tracepipe/instrumentation/pandas_inst.py +11 -3
- tracepipe/safety.py +29 -4
- tracepipe/storage/lineage_store.py +37 -2
- {tracepipe-0.3.3.dist-info → tracepipe-0.3.5.dist-info}/METADATA +21 -1
- {tracepipe-0.3.3.dist-info → tracepipe-0.3.5.dist-info}/RECORD +9 -9
- {tracepipe-0.3.3.dist-info → tracepipe-0.3.5.dist-info}/WHEEL +0 -0
- {tracepipe-0.3.3.dist-info → tracepipe-0.3.5.dist-info}/licenses/LICENSE +0 -0
tracepipe/__init__.py
CHANGED
tracepipe/context.py
CHANGED
|
@@ -63,6 +63,10 @@ class TracePipeContext:
|
|
|
63
63
|
# When > 0, __getitem__[mask] skips capture (parent op will capture)
|
|
64
64
|
self._filter_op_depth: int = 0
|
|
65
65
|
|
|
66
|
+
# Transform operation tracking (prevents double-counting fillna/replace)
|
|
67
|
+
# When > 0, __setitem__ skips capture (transform op will capture)
|
|
68
|
+
self._in_transform_op: int = 0
|
|
69
|
+
|
|
66
70
|
# GroupBy state stack (supports nesting)
|
|
67
71
|
self._groupby_stack: list[dict] = []
|
|
68
72
|
|
|
@@ -22,6 +22,7 @@ from ..safety import (
|
|
|
22
22
|
get_caller_info,
|
|
23
23
|
wrap_pandas_method,
|
|
24
24
|
wrap_pandas_method_inplace,
|
|
25
|
+
wrap_pandas_transform_method,
|
|
25
26
|
)
|
|
26
27
|
from ..utils.value_capture import find_changed_indices_vectorized
|
|
27
28
|
from .apply_capture import instrument_apply_pipe, uninstrument_apply_pipe
|
|
@@ -554,6 +555,9 @@ def _wrap_setitem(original):
|
|
|
554
555
|
|
|
555
556
|
Captures BEFORE state for existing columns, then executes assignment,
|
|
556
557
|
then records the diff with actual old/new values.
|
|
558
|
+
|
|
559
|
+
Skips recording when inside a transform operation (fillna, replace) to
|
|
560
|
+
avoid double-counting cell changes - the transform wrapper will capture.
|
|
557
561
|
"""
|
|
558
562
|
|
|
559
563
|
@wraps(original)
|
|
@@ -565,7 +569,9 @@ def _wrap_setitem(original):
|
|
|
565
569
|
is_new_column = False
|
|
566
570
|
should_track = False
|
|
567
571
|
|
|
568
|
-
if
|
|
572
|
+
# Skip tracking if we're inside a transform operation (fillna, replace)
|
|
573
|
+
# Those operations will capture the change themselves
|
|
574
|
+
if ctx.enabled and isinstance(key, str) and ctx._in_transform_op == 0:
|
|
569
575
|
if key in ctx.watched_columns:
|
|
570
576
|
should_track = True
|
|
571
577
|
if key in self.columns:
|
|
@@ -771,13 +777,15 @@ def instrument_pandas():
|
|
|
771
777
|
wrapped = wrap_filter_method(method_name, original)
|
|
772
778
|
setattr(pd.DataFrame, method_name, wrapped)
|
|
773
779
|
|
|
774
|
-
# === DataFrame transform methods (
|
|
780
|
+
# === DataFrame transform methods (fillna, replace) ===
|
|
781
|
+
# These use wrap_pandas_transform_method to suppress __setitem__ recording
|
|
782
|
+
# during the transform, avoiding double-counting cell changes
|
|
775
783
|
transform_methods = ["fillna", "replace"]
|
|
776
784
|
for method_name in transform_methods:
|
|
777
785
|
if hasattr(pd.DataFrame, method_name):
|
|
778
786
|
original = getattr(pd.DataFrame, method_name)
|
|
779
787
|
_originals[f"DataFrame.{method_name}"] = original
|
|
780
|
-
wrapped =
|
|
788
|
+
wrapped = wrap_pandas_transform_method(method_name, original, _capture_transform)
|
|
781
789
|
setattr(pd.DataFrame, method_name, wrapped)
|
|
782
790
|
|
|
783
791
|
# === astype (no inplace) ===
|
tracepipe/safety.py
CHANGED
|
@@ -103,7 +103,7 @@ def _make_wrapper(
|
|
|
103
103
|
method_name: Name for error messages
|
|
104
104
|
original_method: The original pandas method
|
|
105
105
|
capture_func: func(self, args, kwargs, result, ctx, method_name)
|
|
106
|
-
mode: "standard", "filter", or "
|
|
106
|
+
mode: "standard", "filter", "inplace", or "transform"
|
|
107
107
|
"""
|
|
108
108
|
|
|
109
109
|
@wraps(original_method)
|
|
@@ -112,10 +112,21 @@ def _make_wrapper(
|
|
|
112
112
|
|
|
113
113
|
# === PRE-EXECUTION SETUP ===
|
|
114
114
|
before_snapshot = None
|
|
115
|
+
is_inplace = kwargs.get("inplace", False)
|
|
115
116
|
|
|
116
117
|
if mode == "filter" and ctx.enabled:
|
|
117
118
|
ctx._filter_op_depth += 1
|
|
118
|
-
elif mode == "
|
|
119
|
+
elif mode == "transform" and ctx.enabled:
|
|
120
|
+
# Suppress __setitem__ recording during transform ops (fillna, replace)
|
|
121
|
+
# to avoid double-counting the same cell change
|
|
122
|
+
ctx._in_transform_op += 1
|
|
123
|
+
# Also handle inplace for transform operations
|
|
124
|
+
if is_inplace:
|
|
125
|
+
try:
|
|
126
|
+
before_snapshot = self.copy()
|
|
127
|
+
except Exception:
|
|
128
|
+
pass
|
|
129
|
+
elif mode == "inplace" and ctx.enabled and is_inplace:
|
|
119
130
|
try:
|
|
120
131
|
before_snapshot = self.copy()
|
|
121
132
|
except Exception:
|
|
@@ -127,15 +138,18 @@ def _make_wrapper(
|
|
|
127
138
|
finally:
|
|
128
139
|
if mode == "filter" and ctx.enabled:
|
|
129
140
|
ctx._filter_op_depth -= 1
|
|
141
|
+
elif mode == "transform" and ctx.enabled:
|
|
142
|
+
ctx._in_transform_op -= 1
|
|
130
143
|
|
|
131
144
|
# === CAPTURE LINEAGE (SIDE EFFECT) ===
|
|
132
145
|
# Skip capture if we're inside a filter operation (prevents recursion during export)
|
|
133
146
|
if ctx.enabled and ctx._filter_op_depth == 0:
|
|
134
147
|
try:
|
|
135
|
-
|
|
148
|
+
# Handle inplace for both "inplace" and "transform" modes
|
|
149
|
+
if (mode == "inplace" or mode == "transform") and is_inplace:
|
|
136
150
|
if before_snapshot is not None:
|
|
137
151
|
capture_func(before_snapshot, args, kwargs, self, ctx, method_name)
|
|
138
|
-
elif mode == "inplace" and result is not None:
|
|
152
|
+
elif (mode == "inplace" or mode == "transform") and result is not None:
|
|
139
153
|
capture_func(self, args, kwargs, result, ctx, method_name)
|
|
140
154
|
else:
|
|
141
155
|
capture_func(self, args, kwargs, result, ctx, method_name)
|
|
@@ -176,3 +190,14 @@ def wrap_pandas_method_inplace(
|
|
|
176
190
|
) -> Callable:
|
|
177
191
|
"""Wrap a pandas method that supports inplace=True."""
|
|
178
192
|
return _make_wrapper(method_name, original_method, capture_func, mode="inplace")
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
def wrap_pandas_transform_method(
|
|
196
|
+
method_name: str, original_method: Callable, capture_func: Callable
|
|
197
|
+
) -> Callable:
|
|
198
|
+
"""Wrap a pandas transform method (fillna, replace) that may trigger internal setitem.
|
|
199
|
+
|
|
200
|
+
These methods modify column values and pandas internally uses setitem.
|
|
201
|
+
We suppress setitem recording during these ops to avoid double-counting.
|
|
202
|
+
"""
|
|
203
|
+
return _make_wrapper(method_name, original_method, capture_func, mode="transform")
|
|
@@ -32,6 +32,22 @@ from ..core import (
|
|
|
32
32
|
from ..utils.value_capture import capture_typed_value
|
|
33
33
|
|
|
34
34
|
|
|
35
|
+
def _stable_repr(val) -> str:
|
|
36
|
+
"""Create a stable string representation for deduplication.
|
|
37
|
+
|
|
38
|
+
Handles NaN, None, and other values that don't compare equal to themselves.
|
|
39
|
+
"""
|
|
40
|
+
if val is None:
|
|
41
|
+
return "None"
|
|
42
|
+
# Handle NaN (which doesn't equal itself)
|
|
43
|
+
try:
|
|
44
|
+
if isinstance(val, float) and val != val: # NaN check
|
|
45
|
+
return "NaN"
|
|
46
|
+
except (TypeError, ValueError):
|
|
47
|
+
pass
|
|
48
|
+
return repr(val)
|
|
49
|
+
|
|
50
|
+
|
|
35
51
|
class InMemoryLineageStore:
|
|
36
52
|
"""
|
|
37
53
|
Columnar storage for lineage data using Structure of Arrays (SoA).
|
|
@@ -556,12 +572,15 @@ class InMemoryLineageStore:
|
|
|
556
572
|
Follows merge lineage recursively to build complete cell provenance.
|
|
557
573
|
This is essential for tracking changes that happened before merge operations.
|
|
558
574
|
|
|
575
|
+
Deduplicates events by (col, old_val, new_val, operation) signature to prevent
|
|
576
|
+
cross-pipeline contamination when multiple DataFrames share row IDs.
|
|
577
|
+
|
|
559
578
|
Args:
|
|
560
579
|
row_id: Row ID to trace
|
|
561
580
|
max_depth: Maximum merge depth to follow (prevents infinite loops)
|
|
562
581
|
|
|
563
582
|
Returns:
|
|
564
|
-
List of events in chronological order, including parent row events.
|
|
583
|
+
List of UNIQUE events in chronological order, including parent row events.
|
|
565
584
|
"""
|
|
566
585
|
visited: set[int] = set()
|
|
567
586
|
|
|
@@ -589,7 +608,23 @@ class InMemoryLineageStore:
|
|
|
589
608
|
# Sort by step_id to ensure chronological order across lineage
|
|
590
609
|
all_events.sort(key=lambda e: e["step_id"])
|
|
591
610
|
|
|
592
|
-
|
|
611
|
+
# Deduplicate by (col, old_val, new_val, operation) signature
|
|
612
|
+
# This prevents cross-pipeline contamination when multiple DataFrames
|
|
613
|
+
# share the same row IDs (e.g., df.copy() followed by parallel transforms)
|
|
614
|
+
seen_signatures: set[tuple] = set()
|
|
615
|
+
unique_events = []
|
|
616
|
+
for event in all_events:
|
|
617
|
+
sig = (
|
|
618
|
+
event.get("col"),
|
|
619
|
+
_stable_repr(event.get("old_val")),
|
|
620
|
+
_stable_repr(event.get("new_val")),
|
|
621
|
+
event.get("operation"),
|
|
622
|
+
)
|
|
623
|
+
if sig not in seen_signatures:
|
|
624
|
+
seen_signatures.add(sig)
|
|
625
|
+
unique_events.append(event)
|
|
626
|
+
|
|
627
|
+
return unique_events
|
|
593
628
|
|
|
594
629
|
def get_cell_history_with_lineage(
|
|
595
630
|
self, row_id: int, column: str, max_depth: int = 10
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: tracepipe
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.5
|
|
4
4
|
Summary: Row-level data lineage tracking for pandas pipelines
|
|
5
5
|
Project-URL: Homepage, https://github.com/tracepipe/tracepipe
|
|
6
6
|
Project-URL: Documentation, https://tracepipe.github.io/tracepipe/
|
|
@@ -276,6 +276,26 @@ tp.enable(mode="debug") # Full lineage
|
|
|
276
276
|
|
|
277
277
|
---
|
|
278
278
|
|
|
279
|
+
## Known Limitations
|
|
280
|
+
|
|
281
|
+
TracePipe tracks **cell mutations** (fillna, replace, loc assignment) and **merge provenance** reliably. However, some patterns are not yet fully supported:
|
|
282
|
+
|
|
283
|
+
| Pattern | Status | Notes |
|
|
284
|
+
|---------|--------|-------|
|
|
285
|
+
| `df["col"] = df["col"].fillna(0)` | ✅ Tracked | Series + assignment |
|
|
286
|
+
| `df = df.fillna({"col": 0})` | ✅ Tracked | DataFrame-level fillna |
|
|
287
|
+
| `df.loc[mask, "col"] = val` | ✅ Tracked | Conditional assignment |
|
|
288
|
+
| `df.merge(other, on="key")` | ✅ Tracked | Full provenance in debug mode |
|
|
289
|
+
| `pd.concat([df1, df2])` | ⚠️ Partial | Row IDs preserved, but no "source DataFrame" tracking |
|
|
290
|
+
| `df.drop_duplicates(keep='last')` | ⚠️ Partial | Which row was kept is not tracked |
|
|
291
|
+
| Sort + dedup patterns | ⚠️ Partial | "Latest record wins" logic not traced |
|
|
292
|
+
|
|
293
|
+
**Why?** TracePipe tracks value changes within rows, not row-selection operations. When `drop_duplicates` picks one row over another, that's a provenance decision (not a cell mutation) that isn't currently instrumented.
|
|
294
|
+
|
|
295
|
+
**Planned for 0.4**: Full row-provenance tracking for concat, drop_duplicates, and sort operations.
|
|
296
|
+
|
|
297
|
+
---
|
|
298
|
+
|
|
279
299
|
## Contributing
|
|
280
300
|
|
|
281
301
|
```bash
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
tracepipe/__init__.py,sha256=
|
|
1
|
+
tracepipe/__init__.py,sha256=HK7i2rACJQdbyz5oMZ4z-xo9xJbS0cUqbS2AK6uMHJU,3342
|
|
2
2
|
tracepipe/api.py,sha256=WdcKvvzI3voDt6fxZWa8vjyZQU8lfRshx7T78oj7oFE,13351
|
|
3
|
-
tracepipe/context.py,sha256=
|
|
3
|
+
tracepipe/context.py,sha256=DvwAZGZbLDJ4xoqmS1VnZOBbOI8ZIIErsY9W6GEbFSM,4051
|
|
4
4
|
tracepipe/contracts.py,sha256=m-rjPrgnCiAgKEkweOS7P95jrjDptt5UPdvUlqaV_rU,16226
|
|
5
5
|
tracepipe/convenience.py,sha256=KuDz_ZzNivVG1SS8Srr3plu4CTwFmNhYL4rk3vV6cbE,28421
|
|
6
6
|
tracepipe/core.py,sha256=kAXks694rR0Z4tD7Gyty0TyJGWx2whsSdteYYpHuazo,8010
|
|
7
7
|
tracepipe/debug.py,sha256=6t2GKVZLwn7SJLhrStE9qsmTiVIHATTE3jJPQ2DYtnc,10140
|
|
8
|
-
tracepipe/safety.py,sha256=
|
|
8
|
+
tracepipe/safety.py,sha256=UpzhQj31Dij-DjgT9mY_jPrUpVfcA51gDI2fUos4IUA,6694
|
|
9
9
|
tracepipe/snapshot.py,sha256=OLREzE1_LkWITluG_Bqeb7Y4pAKb8Lb3zJEF3cxnloU,13967
|
|
10
10
|
tracepipe/value_provenance.py,sha256=ogky6aOaZ-6K2uNBQxlXpmCeuvK434Hisj30zesRTd8,9330
|
|
11
11
|
tracepipe/instrumentation/__init__.py,sha256=pd0n6Z9m_V3gcBv097cXWFOZEzAP9sAq1jjQnNRrDZ8,222
|
|
@@ -13,17 +13,17 @@ tracepipe/instrumentation/apply_capture.py,sha256=cMThWzNXqWQENuMrCGTne1hO6fqaQF
|
|
|
13
13
|
tracepipe/instrumentation/filter_capture.py,sha256=onlYLU5bBZSM3WmxM2AFHfktnlx7ReG-brEn5eZ_N10,15830
|
|
14
14
|
tracepipe/instrumentation/indexer_capture.py,sha256=1ATCeJ-uNA1uGiSbgnUx0wdVsIlZGHeUBaFJPXgFQNg,28440
|
|
15
15
|
tracepipe/instrumentation/merge_capture.py,sha256=Eze-PTrn7IXxZRZBYX9R13mOY3diWKAkjp4z-wa1tEk,13349
|
|
16
|
-
tracepipe/instrumentation/pandas_inst.py,sha256=
|
|
16
|
+
tracepipe/instrumentation/pandas_inst.py,sha256=h8RlfwYkYwuftCyBYIETdwHxVCzQM1SBBrbYP7SyjJ8,30047
|
|
17
17
|
tracepipe/instrumentation/series_capture.py,sha256=i7FiA2ndEzS6duIj5y-a7SDfIMl2cCY_jGC1tmG7TGU,11271
|
|
18
18
|
tracepipe/storage/__init__.py,sha256=pGFMfbIgIi2kofVPwYDqe2HTYMYJoabiGjTq77pYi-g,348
|
|
19
19
|
tracepipe/storage/base.py,sha256=7DV_-rp37DjBMr9B1w85hLVYhC8OQShk2PcEhT-n4tE,4894
|
|
20
|
-
tracepipe/storage/lineage_store.py,sha256=
|
|
20
|
+
tracepipe/storage/lineage_store.py,sha256=KhGri2uC_O_43fUivFGEHY6KBDHd1I0O_PPd_KD3L4M,28683
|
|
21
21
|
tracepipe/storage/row_identity.py,sha256=HBU0gTTJlFtFTcAdUCKuX-c9cHa0lo3CDIodDPDgOzA,17161
|
|
22
22
|
tracepipe/utils/__init__.py,sha256=CI_GXViCjdMbu1j6HuzZhoQZEW0sIB6WAve6j5pfOC0,182
|
|
23
23
|
tracepipe/utils/value_capture.py,sha256=wGgegQmJnVHxHbwHSH9di7JAOBChzD3ERJrabZNiayk,4092
|
|
24
24
|
tracepipe/visualization/__init__.py,sha256=M3s44ZTUNEToyghjhQW0FgbmWHKPr4Xc-7iNF6DpI_E,132
|
|
25
25
|
tracepipe/visualization/html_export.py,sha256=G0hfZTJctUCfpun17zXX1NIXhvJZbca6hKmP3rcIjbg,42282
|
|
26
|
-
tracepipe-0.3.
|
|
27
|
-
tracepipe-0.3.
|
|
28
|
-
tracepipe-0.3.
|
|
29
|
-
tracepipe-0.3.
|
|
26
|
+
tracepipe-0.3.5.dist-info/METADATA,sha256=bWidBs8nMW6T6oah8xQum_IjdP7Y1J1inDAn-gfHUCg,10288
|
|
27
|
+
tracepipe-0.3.5.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
28
|
+
tracepipe-0.3.5.dist-info/licenses/LICENSE,sha256=HMOAFHBClL79POwWL-2_aDcx42DJAq7Ce-nwJPvMB9U,1075
|
|
29
|
+
tracepipe-0.3.5.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|