processbehavior 0.2.0__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.
Files changed (56) hide show
  1. processbehavior/__init__.py +133 -0
  2. processbehavior/analysis.py +2944 -0
  3. processbehavior/analysis_dataset.py +361 -0
  4. processbehavior/analysis_result.py +1276 -0
  5. processbehavior/calibration.py +70 -0
  6. processbehavior/capability.py +720 -0
  7. processbehavior/data_preparation.py +792 -0
  8. processbehavior/datasets/__init__.py +37 -0
  9. processbehavior/datasets/data/coffee_shop_demo_long.csv +385 -0
  10. processbehavior/datasets/loaders.py +66 -0
  11. processbehavior/datasets/synthetic.py +1711 -0
  12. processbehavior/derivations.py +602 -0
  13. processbehavior/effects_calculator.py +603 -0
  14. processbehavior/exceptions.py +216 -0
  15. processbehavior/exporters/__init__.py +5 -0
  16. processbehavior/exporters/excel_exporter.py +708 -0
  17. processbehavior/focused_result.py +329 -0
  18. processbehavior/formulation_spec.py +144 -0
  19. processbehavior/loss_function.py +517 -0
  20. processbehavior/maximum_information.py +285 -0
  21. processbehavior/plotting/__init__.py +46 -0
  22. processbehavior/plotting/_math.py +121 -0
  23. processbehavior/plotting/capability_chart.py +858 -0
  24. processbehavior/plotting/contracts.py +176 -0
  25. processbehavior/plotting/control_chart.py +206 -0
  26. processbehavior/plotting/effects_charts.py +640 -0
  27. processbehavior/plotting/lane_boundaries.py +78 -0
  28. processbehavior/plotting/limits.py +157 -0
  29. processbehavior/plotting/maximum_information_chart.py +395 -0
  30. processbehavior/plotting/plotter.py +1469 -0
  31. processbehavior/plotting/renderers.py +660 -0
  32. processbehavior/plotting/report.py +211 -0
  33. processbehavior/plotting/residuals.py +282 -0
  34. processbehavior/plotting/run_rules_viz.py +150 -0
  35. processbehavior/plotting/stats_box.py +183 -0
  36. processbehavior/plotting/themes.py +544 -0
  37. processbehavior/plotting/x_axis_layout.py +474 -0
  38. processbehavior/plotting/zones.py +127 -0
  39. processbehavior/process_behavior.py +1290 -0
  40. processbehavior/py.typed +0 -0
  41. processbehavior/residual_calculator.py +572 -0
  42. processbehavior/result_signals.py +149 -0
  43. processbehavior/result_tabular.py +296 -0
  44. processbehavior/sds_detector.py +1432 -0
  45. processbehavior/signals/__init__.py +14 -0
  46. processbehavior/signals/config.py +435 -0
  47. processbehavior/signals/detector.py +328 -0
  48. processbehavior/signals/detectors.py +368 -0
  49. processbehavior/signals/result.py +232 -0
  50. processbehavior/spc_constants.py +692 -0
  51. processbehavior/study.py +2733 -0
  52. processbehavior/types.py +154 -0
  53. processbehavior-0.2.0.dist-info/METADATA +279 -0
  54. processbehavior-0.2.0.dist-info/RECORD +56 -0
  55. processbehavior-0.2.0.dist-info/WHEEL +4 -0
  56. processbehavior-0.2.0.dist-info/licenses/LICENSE +201 -0
@@ -0,0 +1,216 @@
1
+ """
2
+ Custom exceptions for processbehavior.
3
+
4
+ This module provides a lightweight exception hierarchy for better error handling UX.
5
+ Users can catch errors by category and get self-diagnostic error messages.
6
+
7
+ Exception Hierarchy
8
+ -------------------
9
+ ProcessBehaviorError (base)
10
+ └── ValidationError - Invalid input data, parameters, or configuration
11
+ ├── ColumnNotFoundError - Required column missing from DataFrame
12
+ ├── FactorNotFoundError - Invalid factor/variable name specified
13
+ ├── CalibrationNotSupportedError - Calibration not available on this chart path
14
+ └── ChartNotAvailableError - Chart type invalid or unavailable for this SDS
15
+
16
+ Warnings
17
+ --------
18
+ ProcessBehaviorWarning (UserWarning) - Something was changed or assumed on the
19
+ user's behalf (e.g. garbage tokens converted to NA during cleaning). Filterable
20
+ with ``warnings.simplefilter('ignore', ProcessBehaviorWarning)``.
21
+
22
+ Examples
23
+ --------
24
+ Catch by category:
25
+
26
+ >>> try:
27
+ ... result = study.execute(chart='Xbar')
28
+ ... except ChartNotAvailableError as e:
29
+ ... print(f"Try one of: {study.valid_charts}")
30
+ ... except ValidationError as e:
31
+ ... print(f"Check your data: {e}")
32
+
33
+ Catch all library errors:
34
+
35
+ >>> try:
36
+ ... result = study.execute()
37
+ ... except ProcessBehaviorError as e:
38
+ ... print(f"Analysis failed: {e}")
39
+ """
40
+
41
+ from __future__ import annotations
42
+
43
+
44
+ class ProcessBehaviorError(Exception):
45
+ """
46
+ Base exception for all processbehavior errors.
47
+
48
+ Catch this to handle any error from the library in a single except block.
49
+ """
50
+
51
+ pass
52
+
53
+
54
+ class ValidationError(ProcessBehaviorError, ValueError):
55
+ """
56
+ Invalid input data, parameters, or configuration.
57
+
58
+ Raised when user input fails validation before analysis runs.
59
+ Check error message for specific issue and suggested fix.
60
+
61
+ Also subclasses the built-in ``ValueError`` so that callers (and the
62
+ library's own legacy code being migrated off raw ``ValueError``) that
63
+ ``except ValueError`` continue to work — the raw-``ValueError``→
64
+ ``ValidationError`` migration is therefore non-breaking.
65
+
66
+ Common causes:
67
+ - Invalid column names in formulate()
68
+ - Incompatible parameter combinations
69
+ - Data structure doesn't match requirements
70
+ """
71
+
72
+ pass
73
+
74
+
75
+ class ColumnNotFoundError(ValidationError):
76
+ """
77
+ Required column missing from DataFrame.
78
+
79
+ Raised when a specified column (response, factor, time) doesn't exist
80
+ in the input DataFrame.
81
+
82
+ Attributes
83
+ ----------
84
+ column : str | None
85
+ The column name that was not found
86
+ available : list[str] | None
87
+ List of available column names
88
+
89
+ Suggested actions:
90
+ - Check `pb.cols` for available columns with auto-completion
91
+ - Verify column names match exactly (case-sensitive)
92
+ - Check `df.columns` to see all available columns
93
+ """
94
+
95
+ def __init__(self, message: str, column: str | None = None, available: list[str] | None = None):
96
+ super().__init__(message)
97
+ self.column = column
98
+ self.available = available
99
+
100
+
101
+ class FactorNotFoundError(ValidationError):
102
+ """
103
+ Invalid factor/variable name specified.
104
+
105
+ Raised when a factor or variable name doesn't match any known factors
106
+ in the study. Common causes include typos and case mismatches.
107
+
108
+ Attributes
109
+ ----------
110
+ factor : str | None
111
+ The factor name that was not found
112
+ suggestion : str | None
113
+ A suggested correction (e.g., case-corrected name)
114
+ available : list[str] | None
115
+ List of valid factor/variable names
116
+
117
+ Suggested actions:
118
+ - Check spelling and case (names are case-sensitive)
119
+ - Use `study.factors` to see available factor names
120
+ """
121
+
122
+ def __init__(
123
+ self, message: str, factor: str | None = None, suggestion: str | None = None, available: list[str] | None = None
124
+ ):
125
+ super().__init__(message)
126
+ self.factor = factor
127
+ self.suggestion = suggestion
128
+ self.available = available
129
+
130
+
131
+ class CalibrationNotSupportedError(ValidationError):
132
+ """A calibration was supplied on a chart path that cannot apply it.
133
+
134
+ Calibration is applied on global and grouped (single-chart) Xbar/S/X/mR paths.
135
+ Stratified paths (one chart per stratum) and phased X/mR are a documented
136
+ follow-up, so a calibration passed to one of those is refused rather than
137
+ silently ignored.
138
+
139
+ Ask *before* executing with :meth:`Study.supports_calibration`, which answers
140
+ the same question without raising — preferable to catching this, and far
141
+ preferable to re-deriving the rule client-side.
142
+
143
+ Subclasses :class:`ValidationError`, so existing ``except ValidationError``
144
+ handlers are unaffected.
145
+
146
+ Attributes
147
+ ----------
148
+ context : str | None
149
+ The unsupported path, e.g. ``'stratified Xbar'`` or ``'phased X/mR'``.
150
+
151
+ Examples
152
+ --------
153
+ >>> if study.supports_calibration(chart='X', by=['Machine']):
154
+ ... result = study.execute(chart='X', by=['Machine'], calibration=cal)
155
+ ... else:
156
+ ... result = study.execute(chart='X', by=['Machine'])
157
+ """
158
+
159
+ def __init__(self, message: str, context: str | None = None):
160
+ super().__init__(message)
161
+ self.context = context
162
+
163
+
164
+ class ChartNotAvailableError(ValidationError):
165
+ """
166
+ Chart type invalid or unavailable for this SDS/data structure.
167
+
168
+ Raised when requesting a chart that cannot be produced given the
169
+ current data structure and Sampling Design State (SDS).
170
+
171
+ Attributes
172
+ ----------
173
+ chart : str | None
174
+ The chart type that was requested
175
+ available : list[str] | None
176
+ List of available chart types
177
+
178
+ Suggested actions:
179
+ - Check `study.valid_charts` for available chart types
180
+ - Use `study.why_not(chart_type)` for explanation
181
+ - Use `study.support` DataFrame for full availability matrix
182
+ """
183
+
184
+ def __init__(self, message: str, chart: str | None = None, available: list[str] | None = None):
185
+ super().__init__(message)
186
+ self.chart = chart
187
+ self.available = available
188
+
189
+
190
+ class ProcessBehaviorWarning(UserWarning):
191
+ """
192
+ Something was changed or assumed on your behalf.
193
+
194
+ Raised (as a warning, not an exception) when the library alters input
195
+ rather than rejecting it — most often during the automatic cleaning that
196
+ converts garbage tokens to NA when a DataFrame is loaded.
197
+
198
+ These were previously emitted through ``logging``, which the library never
199
+ configures a handler for, so they were invisible in most sessions and
200
+ could not be filtered programmatically. As warnings they show up by
201
+ default and obey the standard filters.
202
+
203
+ Examples
204
+ --------
205
+ Silence them:
206
+
207
+ >>> import warnings
208
+ >>> warnings.simplefilter('ignore', ProcessBehaviorWarning)
209
+
210
+ Turn them into errors (useful in a validated pipeline where silent
211
+ coercion is unacceptable):
212
+
213
+ >>> warnings.simplefilter('error', ProcessBehaviorWarning)
214
+ """
215
+
216
+ pass
@@ -0,0 +1,5 @@
1
+ """Exporters for analysis results."""
2
+
3
+ from .excel_exporter import ExcelExporter
4
+
5
+ __all__ = ['ExcelExporter']