fastexcel icon indicating copy to clipboard operation
fastexcel copied to clipboard

Coercing dates to strings adds time of the form '00:00:00'

Open severinh opened this issue 7 months ago • 2 comments

How to reproduce

Suppose you have an Excel file with the following mixed-type data:

Header
=DATE(2024, 7, 1)
=DATE(2024, 7, 2)
"some string"

Now lets read this Excel file into a Polars dataframe, which coerces the column to strings: excel_reader.load_sheet(0).to_polars()

This produces the following data frame:

Header
"2024-07-01 00:00:00"
"2024-07-02 00:00:00"
"some string"

Expected behavior

What I would have expected fastexcel to not include the time 00:00:00 for these dates. That is,

Header
"2024-07-01"
"2024-07-02"
"some string"

Test case

Excel sheet: sheet-date.xlsx

def test_date_casting_to_string() -> None:
    excel_reader = fastexcel.read_excel(path_for_fixture("sheet-date.xlsx"))
    sheet = excel_reader.load_sheet(0, column_names=["col1"])
    expected = {
        "col1": ["2024-07-01", "2024-07-02", "some string"],
    }
    pl_assert_frame_equal(sheet.to_polars(), pl.DataFrame(expected))

severinh avatar Jul 17 '24 13:07 severinh