From 855544aff992db68cd3e2875cbc02128941ff5eb Mon Sep 17 00:00:00 2001 From: Akalanka <8133713+boneyag@users.noreply.github.com> Date: Tue, 4 Oct 2022 11:54:24 -0600 Subject: [PATCH] dict comprehension is faster than invoking dict constructor (#676) --- dataprofiler/profilers/data_labeler_column_profile.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/dataprofiler/profilers/data_labeler_column_profile.py b/dataprofiler/profilers/data_labeler_column_profile.py index ae5834bf1..67686dfd4 100644 --- a/dataprofiler/profilers/data_labeler_column_profile.py +++ b/dataprofiler/profilers/data_labeler_column_profile.py @@ -218,9 +218,7 @@ def possible_data_labels(self) -> List[str]: def rank_distribution(self) -> Dict[str, int]: """Return rank distribution.""" if self._rank_distribution is None: - self._rank_distribution = dict( - [(key, 0) for key in self.possible_data_labels] - ) + self._rank_distribution = {key: 0 for key in self.possible_data_labels} return self._rank_distribution @property @@ -289,9 +287,7 @@ def label_representation(self) -> Optional[Dict[str, float]]: if not self.sample_size: return None - label_representation: Dict[str, float] = dict( - [(key, 0) for key in self.possible_data_labels] - ) + label_representation: Dict[str, float] = {key: 0 for key in self.possible_data_labels} total_votes = max(1, sum(list(self.rank_distribution.values()))) for key in label_representation: label_representation[key] = self.rank_distribution[key] / total_votes