Skip to content

Commit 6e8ce68

Browse files
committed
FIX: add nbytes property in Categorical
1 parent e487a30 commit 6e8ce68

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

pandas/core/categorical.py

+4
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,10 @@ def __array__(self, dtype=None):
722722
def T(self):
723723
return self
724724

725+
@property
726+
def nbytes(self):
727+
return self._codes.nbytes + self._categories.values.nbytes
728+
725729
def isnull(self):
726730
"""
727731
Detect missing values

pandas/tests/test_categorical.py

+5
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,11 @@ def test_set_item_nan(self):
884884
exp = np.array([0,1,3,2])
885885
self.assert_numpy_array_equal(cat.codes, exp)
886886

887+
def test_nbytes(self):
888+
cat = pd.Categorical([1,2,3])
889+
exp = cat._codes.nbytes + cat._categories.values.nbytes
890+
self.assertEqual(cat.nbytes, exp)
891+
887892
def test_deprecated_labels(self):
888893
# TODO: labels is deprecated and should be removed in 0.18 or 2017, whatever is earlier
889894
cat = pd.Categorical([1,2,3, np.nan], categories=[1,2,3])

0 commit comments

Comments
 (0)