Skip to content

NA/nan within returned DataFrame via UDF back to Python is parsed to empty string '' instead of NA/nan #1947

@weigao-123

Description

@weigao-123

OS (e.g. Windows 10 or macOS Sierra)

Windows 10

Versions of xlwings, Excel and Python (e.g. 0.11.8, Office 365, Python 3.7)

0.27.7, Office 365, Python 3.7

Describe your issue (incl. Traceback!)

I found that when we return a DataFrame including NA/nan value to Excel using UDF, so that the NA/nan value becomes empty value in the dynamic array in Excel, which is good. But when I try to read this dynamic array back to Python, it turns out that the empty value is parsed into a string with '' instead of NA/nan, which does not make sense. Although I could solve this manually, is there any way that could handle this automatically or it is just a potential issue?

# Your traceback here
Not an error.

Include a minimal code sample to reproduce the issue (and attach a sample workbook if required!)

image

# Your code here
@xw.func
@xw.ret(index=False)
def test_write():
    df = pd.DataFrame({'a': [1, 2], 'b': [3, None]})
    return df


@xw.func
@xw.arg('df', pd.DataFrame, index=False)
def test_read(df, r, c):
    return str(type(df.iloc[int(r)][int(c)]))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions