[Python] Pandas FutureWarning about concatenating DFs with NAs seems biased

Discussão em 'Python' iniciado por Stack, Setembro 10, 2024.

  1. Stack

    Stack Membro Participativo

    I am getting Future Warning with Pandas 2.2.2 when I try to concatenate DFs with Floating Values and Nones.

    But the same won't happen if I use INT instead of FLOAT

    import pandas as pd

    # Block with INT
    df1 = pd.DataFrame({'A': [1], 'B': [4]})
    df2 = pd.DataFrame({'A': [2], 'B': [None]})
    print(len(pd.concat([df1, df2])))

    # Block with FLOAT
    df1 = pd.DataFrame({'A': [1], 'B': [4.0]})
    df2 = pd.DataFrame({'A': [2], 'B': [None]})
    print(len(pd.concat([df1, df2])))


    Block with INT runs fine, while Block with FLOAT gives warning

    Sample output

    2
    ./test.py:18: FutureWarning: The behavior of DataFrame concatenation with empty or all-NA entries is deprecated. In a future version, this will no longer exclude empty or all-NA columns when determining the result dtypes. To retain the old behavior, exclude the relevant entries before the concat operation.
    print(len(pd.concat([df1, df2])))
    2


    Is it expected?

    It doesn't feel like what the warning is trying to convey.

    Also, I have valid content in other columns, why should this create noise.

    I don't think this is duplicate of this: Alternative to .concat() of empty dataframe, now that it is being deprecated?

    Continue reading...

Compartilhe esta Página