Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: cast bools to strings if mixed types #251

Merged
merged 3 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified python/tests/fixtures/fixture-multi-dtypes-columns.xlsx
Binary file not shown.
2 changes: 2 additions & 0 deletions python/tests/test_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def expected_data() -> dict[str, list[Any]]:
"Details": ["Healthcare"] * 7 + ["Something"] * 2,
"Asset ID": ["84444"] * 7 + ["ABC123"] * 2,
"Mixed dates": ["2023-07-21 00:00:00"] * 6 + ["July 23rd"] * 3,
"Mixed bools": ["true"] * 5 + ["false"] * 3 + ["other"],
}


Expand Down Expand Up @@ -92,6 +93,7 @@ def test_sheet_with_mixed_dtypes_and_sample_rows(expected_data: dict[str, list[A
]
expected_data["Asset ID"] = [84444.0] * 7 + [None] * 2
expected_data["Mixed dates"] = [datetime(2023, 7, 21)] * 6 + [None] * 3
expected_data["Mixed bools"] = [True] * 5 + [False] * 3 + [None]

pd_df = sheet.to_pandas()
pd_assert_frame_equal(
Expand Down
1 change: 1 addition & 0 deletions src/types/dtype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ fn int_types() -> &'static HashSet<DType> {
fn string_types() -> &'static HashSet<DType> {
STRING_TYPES_CELL.get_or_init(|| {
HashSet::from([
DType::Bool,
DType::Int,
DType::Float,
DType::String,
Expand Down
2 changes: 2 additions & 0 deletions src/types/python/excelsheet/sheet_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ mod array_impls {
.map(|dt| dt.to_string())
} else if cell.is_datetime_iso() {
cell.get_datetime_iso().map(str::to_string)
} else if cell.is_bool() {
cell.get_bool().map(|v| v.to_string())
} else {
cell.as_string()
}
Expand Down
Loading