Skip to content

Commit

Permalink
feat: cast bools to strings if mixed types (#251)
Browse files Browse the repository at this point in the history
* feat: cast bools to strings if mixed types

* test: rewrite a bit

* test: move to right place
  • Loading branch information
PrettyWood authored Jul 19, 2024
1 parent 5c7c608 commit 415ae26
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 0 deletions.
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

0 comments on commit 415ae26

Please sign in to comment.