@@ -1258,7 +1258,7 @@ def isna(self):
1258
1258
"""
1259
1259
Detect missing values
1260
1260
1261
- Both missing values (-1 in .codes) and NA as a category are detected.
1261
+ Missing values (-1 in .codes) are detected.
1262
1262
1263
1263
Returns
1264
1264
-------
@@ -1273,13 +1273,6 @@ def isna(self):
1273
1273
"""
1274
1274
1275
1275
ret = self ._codes == - 1
1276
-
1277
- # String/object and float categories can hold np.nan
1278
- if self .categories .dtype .kind in ['S' , 'O' , 'f' ]:
1279
- if np .nan in self .categories :
1280
- nan_pos = np .where (isna (self .categories ))[0 ]
1281
- # we only have one NA in categories
1282
- ret = np .logical_or (ret , self ._codes == nan_pos )
1283
1276
return ret
1284
1277
isnull = isna
1285
1278
@@ -1315,16 +1308,14 @@ def dropna(self):
1315
1308
"""
1316
1309
Return the Categorical without null values.
1317
1310
1318
- Both missing values (-1 in .codes) and NA as a category are detected.
1319
- NA is removed from the categories if present.
1311
+ Missing values (-1 in .codes) are detected.
1320
1312
1321
1313
Returns
1322
1314
-------
1323
1315
valid : Categorical
1324
1316
"""
1325
1317
result = self [self .notna ()]
1326
- if isna (result .categories ).any ():
1327
- result = result .remove_categories ([np .nan ])
1318
+
1328
1319
return result
1329
1320
1330
1321
def value_counts (self , dropna = True ):
@@ -1336,7 +1327,7 @@ def value_counts(self, dropna=True):
1336
1327
Parameters
1337
1328
----------
1338
1329
dropna : boolean, default True
1339
- Don't include counts of NaN, even if NaN is a category .
1330
+ Don't include counts of NaN.
1340
1331
1341
1332
Returns
1342
1333
-------
@@ -1348,11 +1339,9 @@ def value_counts(self, dropna=True):
1348
1339
1349
1340
"""
1350
1341
from numpy import bincount
1351
- from pandas import isna , Series , CategoricalIndex
1342
+ from pandas import Series , CategoricalIndex
1352
1343
1353
- obj = (self .remove_categories ([np .nan ]) if dropna and
1354
- isna (self .categories ).any () else self )
1355
- code , cat = obj ._codes , obj .categories
1344
+ code , cat = self ._codes , self .categories
1356
1345
ncat , mask = len (cat ), 0 <= code
1357
1346
ix , clean = np .arange (ncat ), mask .all ()
1358
1347
@@ -1880,15 +1869,6 @@ def __setitem__(self, key, value):
1880
1869
key = np .asarray (key )
1881
1870
1882
1871
lindexer = self .categories .get_indexer (rvalue )
1883
-
1884
- # FIXME: the following can be removed after GH7820 is fixed:
1885
- # https://github.com/pandas-dev/pandas/issues/7820
1886
- # float categories do currently return -1 for np.nan, even if np.nan is
1887
- # included in the index -> "repair" this here
1888
- if isna (rvalue ).any () and isna (self .categories ).any ():
1889
- nan_pos = np .where (isna (self .categories ))[0 ]
1890
- lindexer [lindexer == - 1 ] = nan_pos
1891
-
1892
1872
lindexer = self ._maybe_coerce_indexer (lindexer )
1893
1873
self ._codes [key ] = lindexer
1894
1874
0 commit comments