Skip to content

FutureWarnings should specify a stacklevel #9584

Closed
@njsmith

Description

@njsmith

Running my test suite, I see:

/home/njs/.user-python2.7-64bit-3/local/lib/python2.7/site-packages/pandas/core/categorical.py:443: FutureWarning: Accessing 'levels' is deprecated, use 'categories'
  warn("Accessing 'levels' is deprecated, use 'categories'", FutureWarning)
/home/njs/.user-python2.7-64bit-3/local/lib/python2.7/site-packages/pandas/core/categorical.py:291: RuntimeWarning: Values and categories have different dtypes. Did you mean to use
'Categorical.from_codes(codes, categories)'?
  "'Categorical.from_codes(codes, categories)'?", RuntimeWarning)
/home/njs/.user-python2.7-64bit-3/local/lib/python2.7/site-packages/pandas/core/categorical.py:295: RuntimeWarning: None of the categories were found in values. Did you mean to use
'Categorical.from_codes(codes, categories)'?
  "'Categorical.from_codes(codes, categories)'?", RuntimeWarning)
./home/njs/.user-python2.7-64bit-3/local/lib/python2.7/site-packages/pandas/core/categorical.py:395: FutureWarning: 'labels' is deprecated. Use 'codes' instead
  warnings.warn("'labels' is deprecated. Use 'codes' instead", FutureWarning)

Okay, fair enough. But the problem is that all of the listed lines of code are inside pandas, so I have no idea which parts of my code are actually doing the wrong thing. warnings.warn provides a stacklevel argument, where the idea is that you should pass a non-zero value so that warnings are attributed to the code that actually needs to be changed. E.g., stacklevel=1 means that the code which is doing something wrong is the code which called the function containing the call to warnings.warn.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DeprecateFunctionality to remove in pandas

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions