Skip to content

CLN: use self.dtype internally in Categorical #22513

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 30, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,8 +500,7 @@ def _from_sequence(cls, scalars, dtype=None, copy=False):
def copy(self):
""" Copy constructor. """
return self._constructor(values=self._codes.copy(),
categories=self.categories,
ordered=self.ordered,
dtype=self.dtype,
fastpath=True)

def astype(self, dtype, copy=True):
Expand Down Expand Up @@ -1632,8 +1631,8 @@ def sort_values(self, inplace=False, ascending=True, na_position='last'):
self._codes = codes
return
else:
return self._constructor(values=codes, categories=self.categories,
ordered=self.ordered, fastpath=True)
return self._constructor(values=codes, dtype=self.dtype,
fastpath=True)

def _values_for_rank(self):
"""
Expand Down Expand Up @@ -1777,8 +1776,7 @@ def fillna(self, value=None, method=None, limit=None):
'or Series, but you passed a '
'"{0}"'.format(type(value).__name__))

return self._constructor(values, categories=self.categories,
ordered=self.ordered, fastpath=True)
return self._constructor(values, dtype=self.dtype, fastpath=True)

def take_nd(self, indexer, allow_fill=None, fill_value=None):
"""
Expand Down Expand Up @@ -1823,8 +1821,7 @@ def take_nd(self, indexer, allow_fill=None, fill_value=None):

codes = take(self._codes, indexer, allow_fill=allow_fill,
fill_value=fill_value)
result = self._constructor(codes, categories=self.categories,
ordered=self.ordered, fastpath=True)
result = self._constructor(codes, dtype=self.dtype, fastpath=True)
return result

take = take_nd
Expand All @@ -1843,9 +1840,8 @@ def _slice(self, slicer):
"categorical")
slicer = slicer[1]

_codes = self._codes[slicer]
return self._constructor(values=_codes, categories=self.categories,
ordered=self.ordered, fastpath=True)
codes = self._codes[slicer]
return self._constructor(values=codes, dtype=self.dtype, fastpath=True)

def __len__(self):
"""The length of this Categorical."""
Expand Down Expand Up @@ -2157,8 +2153,8 @@ def mode(self, dropna=True):
good = self._codes != -1
values = self._codes[good]
values = sorted(htable.mode_int64(ensure_int64(values), dropna))
result = self._constructor(values=values, categories=self.categories,
ordered=self.ordered, fastpath=True)
result = self._constructor(values=values, dtype=self.dtype,
fastpath=True)
return result

def unique(self):
Expand Down Expand Up @@ -2298,8 +2294,7 @@ def repeat(self, repeats, *args, **kwargs):
"""
nv.validate_repeat(args, kwargs)
codes = self._codes.repeat(repeats)
return self._constructor(values=codes, categories=self.categories,
ordered=self.ordered, fastpath=True)
return self._constructor(values=codes, dtype=self.dtype, fastpath=True)

# Implement the ExtensionArray interface
@property
Expand Down