Repository: pola-rs/polars
File: py-polars/tests/unit/io/test_spreadsheet.py (Python)

Code before:
    ).drop_nulls()
    assert df2.schema == {
        "cardinality": pl.UInt16,
        "rows_by_key": pl.Float64,
        "iter_groups": pl.Float64,
    }

    df3 = pl.read_excel(
        path_xlsx,
        sheet_name="test4",
        schema_overrides={"cardinality": pl.UInt16},
        read_csv_options={
            "dtypes": {
                "rows_by_key": pl.Float32,
                "iter_groups": pl.Float32,
            },
        },
    ).drop_nulls()
    assert df3.schema == {
        "cardinality": pl.UInt16,
        "rows_by_key": pl.Float32,
        "iter_groups": pl.Float32,
    }

    for workbook_path in (path_xlsx, path_xlsb, path_ods):
        print(workbook_path)
        df4 = pl.read_excel(
            workbook_path,
            sheet_name="test5",
            schema_overrides={"dtm": pl.Datetime("ns"), "dt": pl.Date},
        )
        assert df4.to_dict(False) == {
            "dtm": [
                datetime(1999, 12, 31, 10, 30, 45),
                datetime(2010, 10, 11, 12, 13, 14),
            ],
            "dt": [date(2024, 1, 1), date(2018, 8, 7)],
            "val": [1.5, -0.5],
        }

    with pytest.raises(ParameterCollisionError):
        # cannot specify 'cardinality' in both schema_overrides and read_csv_options
        pl.read_excel(
            path_xlsx,
            sheet_name="test4",
            schema_overrides={"cardinality": pl.UInt16},
            read_csv_options={"dtypes": {"cardinality": pl.Int32}},
        )


def test_unsupported_engine() -> None:

Review comment (refactor):
Forgot to remove this print statement?

```suggestion
```

Code after:
    ).drop_nulls()
    assert df2.schema == {
        "cardinality": pl.UInt16,
        "rows_by_key": pl.Float64,
        "iter_groups": pl.Float64,
    }

    df3 = pl.read_excel(
        path_xlsx,
        sheet_name="test4",
        schema_overrides={"cardinality": pl.UInt16},
        read_csv_options={
            "dtypes": {
                "rows_by_key": pl.Float32,
                "iter_groups": pl.Float32,
            },
        },
    ).drop_nulls()
    assert df3.schema == {
        "cardinality": pl.UInt16,
        "rows_by_key": pl.Float32,
        "iter_groups": pl.Float32,
    }

    for workbook_path in (path_xlsx, path_xlsb, path_ods):
        df4 = pl.read_excel(
            workbook_path,
            sheet_name="test5",
            schema_overrides={"dtm": pl.Datetime("ns"), "dt": pl.Date},
        )
        assert_frame_equal(
            df4,
            pl.DataFrame(
                {
                    "dtm": [
                        datetime(1999, 12, 31, 10, 30, 45),
                        datetime(2010, 10, 11, 12, 13, 14),
                    ],
                    "dt": [date(2024, 1, 1), date(2018, 8, 7)],
                    "val": [1.5, -0.5],
                },
                schema={"dtm": pl.Datetime("ns"), "dt": pl.Date, "val": pl.Float64},
            ),
        )

    with pytest.raises(ParameterCollisionError):
        # cannot specify 'cardinality' in both schema_overrides and read_csv_options
        pl.read_excel(
            path_xlsx,
            sheet_name="test4",
            schema_overrides={"cardinality": pl.UInt16},