From fb1bf7f19a0c97858e1013bb6ffd844e64222af9 Mon Sep 17 00:00:00 2001 From: James Mathews Date: Fri, 28 Jul 2023 16:27:53 -0400 Subject: [PATCH] Implement match case. --- .../db/feature_matrix_extractor.py | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/spatialprofilingtoolbox/db/feature_matrix_extractor.py b/spatialprofilingtoolbox/db/feature_matrix_extractor.py index 56d6e5a12..a80d9316a 100644 --- a/spatialprofilingtoolbox/db/feature_matrix_extractor.py +++ b/spatialprofilingtoolbox/db/feature_matrix_extractor.py @@ -63,23 +63,24 @@ def extract(self, continuous_also: bool=False, ): extraction = None - if self.db_source == DBSource.CURSOR: - extraction = self._extract( - specimen=specimen, - study=study, - continuous_also=continuous_also, - ) - if self.db_source == DBSource.CONFIG_FILE: - with DatabaseConnectionMaker(self.database_config_file) as dcm: - with dcm.get_connection().cursor() as cursor: - self.cursor = cursor - extraction = self._extract( - specimen=specimen, - study=study, - continuous_also=continuous_also, - ) - if self.db_source == DBSource.UNKNOWN: - logger.error('The database source can not be determined.') + match self.db_source: + case DBSource.CURSOR: + extraction = self._extract( + specimen=specimen, + study=study, + continuous_also=continuous_also, + ) + case DBSource.CONFIG_FILE: + with DatabaseConnectionMaker(self.database_config_file) as dcm: + with dcm.get_connection().cursor() as cursor: + self.cursor = cursor + extraction = self._extract( + specimen=specimen, + study=study, + continuous_also=continuous_also, + ) + case DBSource.UNKNOWN: + logger.error('The database source can not be determined.') return extraction def _extract(self,