Skip to content

QST: Is there a work-around for repeated FutureWarnings? #50603

Open
@stev-0

Description

@stev-0

Research

  • I have searched the [pandas] tag on StackOverflow for similar questions.

  • I have asked my usage related question on StackOverflow.

Link to question on StackOverflow

https://stackoverflow.com/questions/75029437/pandas-get-single-warning-message-per-line

Question about pandas

Is repeated warnings expected behaviour when calling the same code multiple times? This is probably more likely to be a Python bug, but to date I haven't discovered how Pandas triggers it and if there is any work-around.

Pandas 1.5.2, Python3.10

import pandas as pd
import warnings

warnings.simplefilter(action='default', category=FutureWarning)

d = {'col1': [1, 2], 'col2': [3, 4], 'col3': [5, 6]}
df = pd.DataFrame(data=d)
a = ['col1','col2']
df[a]

b = set(a)
for i in range(3):
  df[b]

Output of python3 -Wd::FutureWarning test.py

/home/stephen/test.py:16: FutureWarning: Passing a set as an indexer is deprecated and will raise in a future version. Use a list instead.
df[b]
/home/stephen/test.py:16: FutureWarning: Passing a set as an indexer is deprecated and will raise in a future version. Use a list instead.
df[b]
/home/stephen/test.py:16: FutureWarning: Passing a set as an indexer is deprecated and will raise in a future version. Use a list instead.
df[b]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Usage QuestionWarningsWarnings that appear or should be added to pandas

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions