Coverage for dataexcept/__init__.py: 100%

21 statements  

« prev     ^ index     » next       coverage.py v7.15.4, created at 2026-09-03 20:46 +0000

1"""Top-level package for DataExcept. 

2 

3Every exception the package defines is importable straight from here:: 

4 

5 from dataexcept import ValidationError, ModelTrainingError 

6 

7They all derive from :class:`DataExceptError`, so one clause catches every 

8operational exception this package raises:: 

9 

10 except DataExceptError: 

11 ... 

12 

13The domain modules (``datascience_exceptions``, ``pipeline_exceptions`` and so 

14on) remain importable and export the same objects, so both spellings work and 

15refer to the same classes. 

16""" 

17 

18from pathlib import Path 

19 

20try: # Python >=3.11 

21 import tomllib # type: ignore 

22except ModuleNotFoundError: # pragma: no cover - fallback for Python <3.11 

23 import tomli as tomllib # type: ignore 

24 

25from importlib import metadata 

26 

27from . import ( # noqa: F401 

28 database_exceptions, 

29 dataengineering_exceptions, 

30 datascience_exceptions, 

31 exceptions, 

32 io_exceptions, 

33 logging_helpers, 

34 network_exceptions, 

35 pandas_exceptions, 

36 pipeline_exceptions, 

37 security_exceptions, 

38) 

39from .base import DataExceptError, UnpicklableCause, UnpicklableValue 

40from .database_exceptions import ( 

41 DatabaseConnectionError, 

42 DatabaseError, 

43 QueryExecutionError, 

44 TransactionError, 

45) 

46from .dataengineering_exceptions import ( 

47 BatchProcessingError, 

48 DataEngineeringError, 

49 DataTransformationError, 

50 DataWarehouseConnectionError, 

51 ETLJobError, 

52 MissingPartitionError, 

53 SchemaEvolutionError, 

54) 

55from .datascience_exceptions import ( 

56 BiasDetectionError, 

57 ConvergenceError, 

58 CrossValidationError, 

59 DataAugmentationError, 

60 DataDriftError, 

61 DataExportError, 

62 DataFormatError, 

63 DataImbalanceError, 

64 DataLeakageError, 

65 DataLoadingError, 

66 DataNormalizationError, 

67 DataScienceError, 

68 DataValidationError, 

69 DeploymentError, 

70 DimensionalityReductionError, 

71 EarlyStoppingError, 

72 ExperimentTrackingError, 

73 ExplainabilityError, 

74 FeatureEngineeringError, 

75 FeatureScalingError, 

76 FeatureSelectionError, 

77 GPUOutOfMemoryError, 

78 HyperparameterError, 

79 HyperparameterTuningError, 

80 MissingDataError, 

81 ModelCompatibilityError, 

82 ModelEvaluationError, 

83 ModelInferenceError, 

84 ModelSerializationError, 

85 ModelTrainingError, 

86 OutlierDetectionError, 

87 OverfittingError, 

88 PredictionError, 

89 ResourceLimitError, 

90 SchemaMismatchError, 

91 TrainingTimeoutError, 

92 UnderfittingError, 

93) 

94from .exceptions import ( 

95 AuthenticationError, 

96 AuthorizationError, 

97 ConfigurationError, 

98 CronExpressionError, 

99 DependencyError, 

100 DeserializationError, 

101 EmailError, 

102 JobCancellationError, 

103 JobError, 

104 NotificationError, 

105 OperationTimeoutError, 

106 ParsingError, 

107 ResourceNotFoundError, 

108 ScheduleConflictError, 

109 SerializationError, 

110 ServiceConnectionError, 

111 ValidationError, 

112 WebhookError, 

113) 

114from .io_exceptions import ( 

115 CustomIOError, 

116 FileLockError, 

117 FileReadError, 

118 FileWriteError, 

119) 

120from .logging_helpers import ( 

121 Context, 

122 log_and_raise, 

123 log_exception, 

124 log_then_raise, 

125) 

126from .network_exceptions import ( 

127 ConnectionTimeoutError, 

128 HostUnreachableError, 

129 NetworkError, 

130 ProtocolError, 

131) 

132from .pandas_exceptions import ( 

133 DtypeMismatchError, 

134 IndexAlignmentError, 

135 MergeKeyError, 

136 MissingColumnError, 

137 PandasError, 

138 PandasIOError, 

139) 

140from .pipeline_exceptions import ( 

141 ApiError, 

142 DataFetchError, 

143 ExternalServiceError, 

144 FeaturePreprocessingError, 

145 PipelineError, 

146 PipelineNotificationError, 

147 PreprocessingError, 

148 RetryLimitExceededError, 

149 ServiceAuthenticationError, 

150 ServiceAuthorizationError, 

151 ServiceTimeoutError, 

152 StorageError, 

153 TimeDeltaTooLargeError, 

154 TypeCheckError, 

155) 

156from .security_exceptions import ( 

157 DecryptionError, 

158 EncryptionError, 

159 InvalidTokenError, 

160 SecurityError, 

161) 

162from .serialization import exception_to_dict, exception_to_json 

163from .wrapping import wrap, wrapping 

164 

165__all__ = [ 

166 # The root of the hierarchy: catches every operational exception the 

167 # package raises. 

168 "DataExceptError", 

169 # Placeholders for state that could not survive serialization. 

170 "UnpicklableCause", 

171 "UnpicklableValue", 

172 # Every exception class the package defines. 

173 "ApiError", 

174 "AuthenticationError", 

175 "AuthorizationError", 

176 "BatchProcessingError", 

177 "BiasDetectionError", 

178 "ConfigurationError", 

179 "ConnectionTimeoutError", 

180 "ConvergenceError", 

181 "CronExpressionError", 

182 "CrossValidationError", 

183 "CustomIOError", 

184 "DataAugmentationError", 

185 "DataDriftError", 

186 "DataEngineeringError", 

187 "DataExportError", 

188 "DataFetchError", 

189 "DataFormatError", 

190 "DataImbalanceError", 

191 "DataLeakageError", 

192 "DataLoadingError", 

193 "DataNormalizationError", 

194 "DataScienceError", 

195 "DataTransformationError", 

196 "DataValidationError", 

197 "DataWarehouseConnectionError", 

198 "DatabaseConnectionError", 

199 "DatabaseError", 

200 "DecryptionError", 

201 "DependencyError", 

202 "DeploymentError", 

203 "DeserializationError", 

204 "DimensionalityReductionError", 

205 "DtypeMismatchError", 

206 "ETLJobError", 

207 "EarlyStoppingError", 

208 "EmailError", 

209 "EncryptionError", 

210 "ExperimentTrackingError", 

211 "ExplainabilityError", 

212 "ExternalServiceError", 

213 "FeatureEngineeringError", 

214 "FeaturePreprocessingError", 

215 "FeatureScalingError", 

216 "FeatureSelectionError", 

217 "FileLockError", 

218 "FileReadError", 

219 "FileWriteError", 

220 "GPUOutOfMemoryError", 

221 "HostUnreachableError", 

222 "HyperparameterError", 

223 "HyperparameterTuningError", 

224 "IndexAlignmentError", 

225 "InvalidTokenError", 

226 "JobCancellationError", 

227 "JobError", 

228 "MergeKeyError", 

229 "MissingColumnError", 

230 "MissingDataError", 

231 "MissingPartitionError", 

232 "ModelCompatibilityError", 

233 "ModelEvaluationError", 

234 "ModelInferenceError", 

235 "ModelSerializationError", 

236 "ModelTrainingError", 

237 "NetworkError", 

238 "NotificationError", 

239 "OperationTimeoutError", 

240 "OutlierDetectionError", 

241 "OverfittingError", 

242 "PandasError", 

243 "PandasIOError", 

244 "ParsingError", 

245 "PipelineError", 

246 "PipelineNotificationError", 

247 "PredictionError", 

248 "PreprocessingError", 

249 "ProtocolError", 

250 "QueryExecutionError", 

251 "ResourceLimitError", 

252 "ResourceNotFoundError", 

253 "RetryLimitExceededError", 

254 "ScheduleConflictError", 

255 "SchemaEvolutionError", 

256 "SchemaMismatchError", 

257 "SecurityError", 

258 "SerializationError", 

259 "ServiceAuthenticationError", 

260 "ServiceAuthorizationError", 

261 "ServiceConnectionError", 

262 "ServiceTimeoutError", 

263 "StorageError", 

264 "TimeDeltaTooLargeError", 

265 "TrainingTimeoutError", 

266 "TransactionError", 

267 "TypeCheckError", 

268 "UnderfittingError", 

269 "ValidationError", 

270 "WebhookError", 

271 # Turning a third-party exception into one of these. 

272 "wrap", 

273 "wrapping", 

274 # Structured serialization for APIs, queues and telemetry. 

275 "exception_to_dict", 

276 "exception_to_json", 

277 # Logging helpers. 

278 "Context", 

279 "log_and_raise", 

280 "log_exception", 

281 "log_then_raise", 

282 # Domain modules, for callers who prefer a qualified import. 

283 "database_exceptions", 

284 "dataengineering_exceptions", 

285 "datascience_exceptions", 

286 "exceptions", 

287 "io_exceptions", 

288 "logging_helpers", 

289 "network_exceptions", 

290 "pandas_exceptions", 

291 "pipeline_exceptions", 

292 "security_exceptions", 

293] 

294 

295try: 

296 __version__ = metadata.version("DataExcept") 

297except metadata.PackageNotFoundError: # pragma: no cover - fallback during dev 

298 _root = Path(__file__).resolve().parents[1] 

299 with open(_root / "pyproject.toml", "rb") as _f: 

300 __version__ = tomllib.load(_f)["project"]["version"]