Skip to content

Commit 3502f83

Browse files
feat: support casting string to integer or float (#59)
1 parent 632caec commit 3502f83

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

bigframes/dtypes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ def cast_ibis_value(
313313
ibis_dtypes.string,
314314
),
315315
ibis_dtypes.float64: (ibis_dtypes.string, ibis_dtypes.int64),
316-
ibis_dtypes.string: (),
316+
ibis_dtypes.string: (ibis_dtypes.int64, ibis_dtypes.float64),
317317
ibis_dtypes.date: (),
318318
ibis_dtypes.time: (),
319319
ibis_dtypes.timestamp: (ibis_dtypes.Timestamp(timezone="UTC"),),

tests/system/small/test_series.py

+23
Original file line numberDiff line numberDiff line change
@@ -2389,6 +2389,29 @@ def test_astype(scalars_df_index, scalars_pandas_df_index, column, to_type):
23892389
pd.testing.assert_series_equal(bf_result, pd_result)
23902390

23912391

2392+
def test_string_astype_int():
2393+
pd_series = pd.Series(["4", "-7", "0", " -03"])
2394+
bf_series = series.Series(pd_series)
2395+
2396+
pd_result = pd_series.astype("Int64")
2397+
bf_result = bf_series.astype("Int64").to_pandas()
2398+
2399+
pd.testing.assert_series_equal(bf_result, pd_result, check_index_type=False)
2400+
2401+
2402+
def test_string_astype_float():
2403+
pd_series = pd.Series(
2404+
["1", "-1", "-0", "000", " -03.235", "naN", "-inf", "INf", ".33", "7.235e-8"]
2405+
)
2406+
2407+
bf_series = series.Series(pd_series)
2408+
2409+
pd_result = pd_series.astype("Float64")
2410+
bf_result = bf_series.astype("Float64").to_pandas()
2411+
2412+
pd.testing.assert_series_equal(bf_result, pd_result, check_index_type=False)
2413+
2414+
23922415
@pytest.mark.parametrize(
23932416
"index",
23942417
[0, 5, -2],

0 commit comments

Comments
 (0)