Skip to content

Commit 49cba45

Browse files
committed
WARN: remove obsolete warnings
1 parent 8dac633 commit 49cba45

File tree

3 files changed

+6
-29
lines changed

3 files changed

+6
-29
lines changed

doc/source/whatsnew/v0.22.0.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Deprecations
6060
Removal of prior version deprecations/changes
6161
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6262

63-
-
63+
- The warnings for construction of a ``Categorical`` in the form ``Categorical(codes, categories)`` have been removed (:issue:`8074`)
6464
-
6565
-
6666

pandas/core/categorical.py

-22
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
is_timedelta64_dtype,
2626
is_categorical,
2727
is_categorical_dtype,
28-
is_integer_dtype,
2928
is_list_like, is_sequence,
3029
is_scalar,
3130
is_dict_like)
@@ -352,29 +351,8 @@ def __init__(self, values, categories=None, ordered=None, dtype=None,
352351
dtype = CategoricalDtype(categories, ordered)
353352

354353
else:
355-
# there were two ways if categories are present
356-
# - the old one, where each value is a int pointer to the levels
357-
# array -> not anymore possible, but code outside of pandas could
358-
# call us like that, so make some checks
359-
# - the new one, where each value is also in the categories array
360-
# (or np.nan)
361-
362354
codes = _get_codes_for_values(values, dtype.categories)
363355

364-
# TODO: check for old style usage. These warnings should be removes
365-
# after 0.18/ in 2016
366-
if (is_integer_dtype(values) and
367-
not is_integer_dtype(dtype.categories)):
368-
warn("Values and categories have different dtypes. Did you "
369-
"mean to use\n'Categorical.from_codes(codes, "
370-
"categories)'?", RuntimeWarning, stacklevel=2)
371-
372-
if (len(values) and is_integer_dtype(values) and
373-
(codes == -1).all()):
374-
warn("None of the categories were found in values. Did you "
375-
"mean to use\n'Categorical.from_codes(codes, "
376-
"categories)'?", RuntimeWarning, stacklevel=2)
377-
378356
if null_mask.any():
379357
# Reinsert -1 placeholders for previously removed missing values
380358
full_codes = - np.ones(null_mask.shape, dtype=codes.dtype)

pandas/tests/test_categorical.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -306,20 +306,19 @@ def f():
306306
assert len(cat.codes) == 1
307307
assert cat.codes[0] == 0
308308

309-
# Catch old style constructor useage: two arrays, codes + categories
310-
# We can only catch two cases:
309+
# Catches - now disabled - for old style constructor useage:
310+
# two arrays, codes + categories
311311
# - when the first is an integer dtype and the second is not
312312
# - when the resulting codes are all -1/NaN
313-
with tm.assert_produces_warning(RuntimeWarning):
313+
with tm.assert_produces_warning(None):
314314
c_old = Categorical([0, 1, 2, 0, 1, 2],
315315
categories=["a", "b", "c"]) # noqa
316316

317-
with tm.assert_produces_warning(RuntimeWarning):
317+
with tm.assert_produces_warning(None):
318318
c_old = Categorical([0, 1, 2, 0, 1, 2], # noqa
319319
categories=[3, 4, 5])
320320

321-
# the next one are from the old docs, but unfortunately these don't
322-
# trigger :-(
321+
# the next one are from the old docs
323322
with tm.assert_produces_warning(None):
324323
c_old2 = Categorical([0, 1, 2, 0, 1, 2], [1, 2, 3]) # noqa
325324
cat = Categorical([1, 2], categories=[1, 2, 3])

0 commit comments

Comments
 (0)