Skip to content

Commit

Permalink
dict comprehension is faster than invoking dict constructor (#676)
Browse files Browse the repository at this point in the history
  • Loading branch information
boneyag committed Oct 4, 2022
1 parent 554154b commit 855544a
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions dataprofiler/profilers/data_labeler_column_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 855544a

Please sign in to comment.