From 712fe62ae9273b2e58056f48e1be547e9f9d0a72 Mon Sep 17 00:00:00 2001 From: R-Palazzo Date: Fri, 11 Aug 2023 17:52:31 +0100 Subject: [PATCH] use fill_value --- rdt/transformers/categorical.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/rdt/transformers/categorical.py b/rdt/transformers/categorical.py index dfb96c56e..d04da5998 100644 --- a/rdt/transformers/categorical.py +++ b/rdt/transformers/categorical.py @@ -128,8 +128,7 @@ def _fit(self, data): labels = self._order_categories(labels) freq = data.value_counts(normalize=True, dropna=False) nan_value = freq[np.nan] if np.nan in freq.index else None - freq = freq.reindex(labels).array - freq[np.isnan(freq)] = nan_value + freq = freq.reindex(labels, fill_value=nan_value).array self.frequencies, self.intervals = self._compute_frequencies_intervals(labels, freq) @@ -269,8 +268,7 @@ def _fit(self, data): freq = data.value_counts(normalize=True, dropna=False) nan_value = freq[np.nan] if np.nan in freq.index else None - freq = freq.reindex(self.order).array - freq[np.isnan(freq)] = nan_value + freq = freq.reindex(self.order, fill_value=nan_value).array self.frequencies, self.intervals = self._compute_frequencies_intervals(self.order, freq)