minor inconsistency in Categorical.remove_categories error message · Issue #28669 · pandas-dev/pandas (original) (raw)
mypy error: pandas\core\arrays\categorical.py:1125:13: error: Incompatible types in assignment (expression has type "List[Any]", variable has type "Set[Any]") [assignment]
Code Sample, a copy-pastable example if possible
Python 3.7.4 (default, Aug 9 2019, 18:34:13) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32 Type "help", "copyright", "credits" or "license" for more information.
import numpy as np import pandas as pd pd.version '0.26.0.dev0+537.gd2bc6a497.dirty'
cat = pd.Categorical(["a", "b", "c", "a"], ordered=True)
cat [a, b, c, a] Categories (3, object): [a < b < c]
cat = cat.remove_categories(["c"]) cat [a, b, NaN, a] Categories (2, object): [a < b]
cat = cat.remove_categories(["c"]) Traceback (most recent call last): File "", line 1, in File "C:\Users\simon\pandas-simonjayhawkins\pandas\core\arrays\categorical.py", line 1130, in remove_categories raise ValueError(msg.format(not_included=not_included)) ValueError: removals must all be in old categories: {'c'}
cat = cat.remove_categories(["c", np.nan]) Traceback (most recent call last): File "", line 1, in File "C:\Users\simon\pandas-simonjayhawkins\pandas\core\arrays\categorical.py", line 1130, in remove_categories raise ValueError(msg.format(not_included=not_included)) ValueError: removals must all be in old categories: ['c'] cat [a, b, NaN, a] Categories (2, object): [a < b]
Problem description
The error message shows invalid removals as a set or a list depending on whether the removal list contains a null value.
Expected Output
consistent message. preferably as a list.
Output of pd.show_versions()
INSTALLED VERSIONS
commit : d2bc6a4
python : 3.7.4.final.0
python-bits : 64
OS : Windows
OS-release : 10
machine : AMD64
processor : Intel64 Family 6 Model 58 Stepping 9, GenuineIntel
byteorder : little
LC_ALL : None
LANG : en_GB.UTF-8
LOCALE : None.None
pandas : 0.26.0.dev0+537.gd2bc6a497.dirty
numpy : 1.16.4
pytz : 2019.2
dateutil : 2.8.0
pip : 19.2.2
setuptools : 41.0.1
Cython : 0.29.13
pytest : 5.0.1
hypothesis : 4.32.2
sphinx : 1.8.5
blosc : None
feather : None
xlsxwriter : 1.1.8
lxml.etree : 4.4.1
html5lib : 1.0.1
pymysql : None
psycopg2 : None
jinja2 : 2.10.1
IPython : 7.8.0
pandas_datareader: None
bs4 : 4.7.1
bottleneck : 1.2.1
fastparquet : 0.3.0
gcsfs : None
lxml.etree : 4.4.1
matplotlib : 3.1.1
numexpr : 2.7.0
odfpy : None
openpyxl : 2.6.2
pandas_gbq : None
pyarrow : 0.13.0
pytables : None
s3fs : 0.2.1
scipy : 1.3.1
sqlalchemy : 1.3.7
tables : 3.5.2
xarray : 0.12.1
xlrd : 1.2.0
xlwt : 1.3.0
xlsxwriter : 1.1.8