1010
1111from __future__ import annotations
1212
13- from typing import Any , NotRequired , TypedDict
13+ from typing import Any , TypedDict
1414
1515from databeak .models import CellValue
1616
1717__all__ = [
1818 "CellValue" ,
19- "ColumnAnalysis" ,
20- "ColumnProfile" ,
21- "ColumnRenameResult" ,
22- "ColumnSelectionResult" ,
23- "ColumnStatistics" ,
24- "ConfigDict" ,
25- "CsvDataResource" ,
26- "CsvReadParams" ,
2719 "DataDict" ,
28- "DataPreviewRecord" ,
2920 "DataPreviewResult" ,
30- "DataProfileResult" ,
31- "DataSessionMetadata" ,
32- "DataStatisticsDict" ,
3321 "DataValidationIssues" ,
34- "ErrorDetails" ,
35- "ExportOptions" ,
3622 "InternalDataSummary" ,
3723 "MetadataDict" ,
38- "OperationMetadata" ,
39- "OperationResultDict" ,
40- "QualityCheckResult" ,
41- "RowUpdateResult" ,
42- "ServerConfig" ,
43- "SessionMetadataDict" ,
44- "SortSpecification" ,
45- "ToolConfig" ,
46- "TransformationPipeline" ,
47- "TransformationStep" ,
48- "UpdateColumnOperation" ,
4924 "ValidationResult" ,
5025]
5126
5227
53- # Validation and Quality Check Results
28+ # Validation Results (used in validators and data models)
5429class ValidationResult (TypedDict ):
5530 """Result of DataFrame schema validation."""
5631
@@ -67,267 +42,22 @@ class DataValidationIssues(TypedDict):
6742 info : dict [str , Any ] # Any justified: flexible validation metadata
6843
6944
70- class QualityCheckResult (TypedDict ):
71- """Result of data quality assessment."""
72-
73- rule_name : str
74- passed : bool
75- score : float
76- message : str
77- details : NotRequired [dict [str , Any ]] # Any justified: flexible rule-specific data
78-
79-
80- class DataStatisticsDict (TypedDict ):
81- """Statistical summary of column data (internal use - use DataStatistics Pydantic model for API responses)."""
82-
83- count : int
84- mean : NotRequired [float ] # Only for numeric columns
85- std : NotRequired [float ] # Only for numeric columns
86- min : NotRequired [CellValue ]
87- max : NotRequired [CellValue ]
88- unique_count : int
89- null_count : int
90- dtype : str
91-
92-
93- class ColumnProfile (TypedDict ):
94- """Comprehensive column profiling information."""
95-
96- name : str
97- dtype : str
98- statistics : DataStatisticsDict
99- sample_values : list [CellValue ]
100- quality_issues : list [str ]
101-
102-
103- # Session and Operation Metadata
104- class SessionMetadataDict (TypedDict ):
105- """Session state and configuration metadata (internal use)."""
106-
107- created_at : str
108- last_accessed : str
109- operations_count : int
110- data_shape : NotRequired [tuple [int , int ]] # (rows, columns) if data loaded
111-
112-
113- class DataSessionMetadata (TypedDict ):
114- """Metadata stored in DataSession for loaded data."""
115-
116- file_path : str | None
117- shape : tuple [int , int ]
118- columns : list [str ]
119- dtypes : dict [str , str ]
120- loaded_at : str
121-
122-
123- class OperationMetadata (TypedDict ):
124- """Metadata for tracking operations in session history."""
125-
126- operation_type : str
127- timestamp : str
128- parameters : dict [str , CellValue ]
129- rows_affected : NotRequired [int ]
130- columns_affected : NotRequired [list [str ]]
131- execution_time_ms : NotRequired [float ]
132-
133-
134- class SortSpecification (TypedDict ):
135- """Sort specification for column sorting."""
136-
137- column : str
138- ascending : bool
139-
140-
141- # I/O and Data Processing
142- class CsvReadParams (TypedDict ):
143- """Parameters for CSV reading operations."""
144-
145- sep : NotRequired [str ]
146- header : NotRequired [int | None ]
147- names : NotRequired [list [str ]]
148- dtype : NotRequired [dict [str , str ]]
149- parse_dates : NotRequired [list [str ]]
150- encoding : NotRequired [str ]
151- skiprows : NotRequired [int ]
152- nrows : NotRequired [int ]
153-
154-
155- class ExportOptions (TypedDict ):
156- """Options for data export operations."""
157-
158- format : str # 'csv', 'json', 'excel', etc.
159- include_index : bool
160- encoding : NotRequired [str ]
161- sep : NotRequired [str ] # For CSV
162- sheet_name : NotRequired [str ] # For Excel
163-
164-
165- # Data Transformation Structures
166- class TransformationStep (TypedDict ):
167- """Single step in a data transformation pipeline."""
168-
169- operation : str
170- parameters : dict [str , CellValue ]
171- target_columns : NotRequired [list [str ]]
172-
173-
174- class TransformationPipeline (TypedDict ):
175- """Complete transformation pipeline specification."""
176-
177- steps : list [TransformationStep ]
178- description : NotRequired [str ]
179- validation_rules : NotRequired [list [str ]]
180-
181-
182- # Column Operation Structures
183- class UpdateColumnOperation (TypedDict ):
184- """Column update operation specification."""
185-
186- operation_type : str # "replace", "map", "apply", "fillna"
187- value : NotRequired [CellValue ] # For replace/fillna operations
188- old_value : NotRequired [CellValue ] # For replace operations
189- new_value : NotRequired [CellValue ] # For replace operations
190- mapping : NotRequired [dict [str , CellValue ]] # For map operations
191- expression : NotRequired [str ] # For apply operations
192- fill_method : NotRequired [str ] # For fillna operations
193-
194-
195- class ColumnStatistics (TypedDict ):
196- """Statistical information for a column."""
197-
198- count : int
199- null_count : int
200- unique_count : int
201- dtype : str
202- mean : NotRequired [float ] # Numeric columns only
203- std : NotRequired [float ] # Numeric columns only
204- min : NotRequired [CellValue ]
205- max : NotRequired [CellValue ]
206- sum : NotRequired [float ] # Numeric columns only
207- variance : NotRequired [float ] # Numeric columns only
208- skewness : NotRequired [float ] # Numeric columns only
209- kurtosis : NotRequired [float ] # Numeric columns only
210-
211-
212- # Internal operation results (for legacy transformation functions)
213- class ColumnSelectionResult (TypedDict ):
214- """Result of internal column selection operation."""
215-
216- session_id : str
217- selected_columns : list [str ]
218- columns_before : int
219- columns_after : int
220-
221-
222- class RowUpdateResult (TypedDict ):
223- """Result of internal row update operation."""
224-
225- session_id : str
226- row_index : int
227- updated_fields : dict [str , CellValue ]
228- columns_modified : list [str ]
229-
230-
231- class ColumnRenameResult (TypedDict ):
232- """Result of internal column rename operation."""
233-
234- session_id : str
235- renamed : dict [str , str ] # old_name -> new_name mapping
236- columns : list [str ] # Final column list after rename
237-
238-
239- # Tool Response Components
240- class OperationResultDict (TypedDict ):
241- """Standard operation result structure (internal use - use OperationResult Pydantic model for API responses)."""
242-
243- success : bool
244- operation_type : str
245- rows_affected : int
246- columns_affected : list [str ]
247- execution_time_ms : float
248- message : NotRequired [str ]
249-
250-
251- class ErrorDetails (TypedDict ):
252- """Detailed error information."""
253-
254- error_type : str
255- message : str
256- parameter : NotRequired [str ]
257- suggested_fix : NotRequired [str ]
258-
259-
260- # Discovery and Analysis Results
261- class ColumnAnalysis (TypedDict ):
262- """Analysis results for a single column."""
263-
264- column_name : str
265- data_type : str
266- unique_values : int
267- null_percentage : float
268- sample_values : list [CellValue ]
269- patterns : NotRequired [list [str ]]
270- anomalies : NotRequired [list [str ]]
271-
272-
273- class DataProfileResult (TypedDict ):
274- """Complete data profiling results."""
275-
276- total_rows : int
277- total_columns : int
278- memory_usage_mb : float
279- column_analyses : list [ColumnAnalysis ]
280- correlations : NotRequired [dict [str , dict [str , float ]]]
281- summary_statistics : NotRequired [dict [str , DataStatisticsDict ]]
282-
283-
284- # Configuration and Settings
285- class ServerConfig (TypedDict ):
286- """Server configuration parameters."""
287-
288- host : str
289- port : int
290- debug : bool
291- session_timeout_minutes : int
292- max_memory_mb : NotRequired [int ]
293-
294-
295- class ToolConfig (TypedDict ):
296- """Individual tool configuration."""
297-
298- enabled : bool
299- timeout_seconds : NotRequired [int ]
300- memory_limit_mb : NotRequired [int ]
301- validation_level : NotRequired [str ] # 'strict', 'normal', 'permissive'
302-
303-
304- # Data Preview Structures
305- class DataPreviewRecord (TypedDict ):
306- """Single record in data preview with row index."""
307-
308- __row_index__ : int # Original DataFrame row index
309- # Additional fields are column data as CellValue
310-
311-
45+ # Data Preview Structure (used in services for internal operations)
31246class DataPreviewResult (TypedDict ):
313- """Complete data preview with metadata."""
47+ """Complete data preview with metadata.
48+
49+ Used internally by data_operations.py. Fields map to DataPreview Pydantic model
50+ but with different naming for backward compatibility.
51+ """
31452
31553 records : list [dict [str , CellValue ]] # Preview records with actual column data
31654 total_rows : int
317- total_columns : int # Required by io_server.py
55+ total_columns : int
31856 columns : list [str ]
31957 preview_rows : int
32058
32159
322- class CsvDataResource (TypedDict ):
323- """CSV data resource response for MCP resource endpoint."""
324-
325- session_id : str
326- shape : tuple [int , int ] # (rows, columns)
327- preview : DataPreviewResult # Enhanced preview data with indices
328- columns_info : dict [str , Any ] # Any justified: flexible column metadata
329-
330-
60+ # Internal data structures (used in services)
33161class InternalDataSummary (TypedDict ):
33262 """Internal data summary structure (not an MCP tool response)."""
33363
@@ -340,7 +70,6 @@ class InternalDataSummary(TypedDict):
34070 preview : DataPreviewResult
34171
34272
343- # Legacy compatibility - gradually replace these
73+ # Type aliases for common data patterns
34474DataDict = dict [str , CellValue ] # Structured data with known value types
34575MetadataDict = dict [str , str | int | float | bool ] # Metadata with primitive types
346- ConfigDict = dict [str , str | int | bool ] # Configuration with known types
0 commit comments