mirror of
https://github.com/wassname/catalyst.git
synced 2026-09-09 11:19:23 +08:00
Revert "MAINT: Remove support for custom string Column missing values."
This reverts commit 1b1e842e2339d6d0ee40cdfe34dcd27b4e4a7c0c.
This commit is contained in:
@@ -284,28 +284,11 @@ class LabelArray(ndarray):
|
||||
"""
|
||||
if len(self.shape) > 1:
|
||||
raise ValueError("Can't convert a 2D array to a categorical.")
|
||||
|
||||
missing_code = self.reverse_categories[self.missing_value]
|
||||
raw_codes = self.as_int_array()
|
||||
# As of pandas 0.18, putting null values in pandas categoricals is
|
||||
# deprecated. The preferred representation is to pass -1 as the code
|
||||
# for missing values.
|
||||
if missing_code == 0:
|
||||
# This is just a performance optimization. It should produce the
|
||||
# same results as below.
|
||||
codes = raw_codes - 1
|
||||
categories = self.categories[1:]
|
||||
else:
|
||||
# subtract 1 for anything greater than the missing code, and set
|
||||
# the missing code to -1.
|
||||
codes = raw_codes.copy()
|
||||
codes[codes > missing_code] -= 1
|
||||
codes[codes == missing_code] = -1
|
||||
categories = self.categories[self.categories != self.missing_value]
|
||||
|
||||
return pd.Categorical.from_codes(
|
||||
codes,
|
||||
categories,
|
||||
self.as_int_array(),
|
||||
# We need to make a copy because pandas >= 0.17 fails if this
|
||||
# buffer isn't writeable.
|
||||
self.categories.copy(),
|
||||
ordered=False,
|
||||
name=name,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user