Skip to content

Commit 55fefe7

Browse files
committed
fix: support setitem with NaTType
1 parent c0cefd3 commit 55fefe7

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

bigframes/core/array_value.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,10 +324,6 @@ def create_constant(
324324
value: typing.Any,
325325
dtype: typing.Optional[bigframes.dtypes.Dtype],
326326
) -> Tuple[ArrayValue, str]:
327-
if pandas.isna(value):
328-
# Need to assign a data type when value is NaN.
329-
dtype = dtype or bigframes.dtypes.DEFAULT_DTYPE
330-
331327
return self.project_to_id(ex.const(value, dtype))
332328

333329
def select_columns(

bigframes/dtypes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -674,14 +674,14 @@ def infer_literal_type(literal) -> typing.Optional[Dtype]:
674674
pa.field(key, field_type, nullable=(not pa.types.is_list(field_type)))
675675
)
676676
return pd.ArrowDtype(pa.struct(fields))
677-
if pd.isna(literal):
678-
return None # Null value without a definite type
679677
# Make sure to check datetime before date as datetimes are also dates
680678
if isinstance(literal, (datetime.datetime, pd.Timestamp)):
681679
if literal.tzinfo is not None:
682680
return TIMESTAMP_DTYPE
683681
else:
684682
return DATETIME_DTYPE
683+
if pd.isna(literal):
684+
return None # Null value without a definite type
685685
from_python_type = _infer_dtype_from_python_type(type(literal))
686686
if from_python_type is not None:
687687
return from_python_type

tests/system/small/test_dataframe.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3764,6 +3764,12 @@ def test_at_no_duplicate(scalars_df_index, scalars_pandas_df_index):
37643764
assert bf_result == pd_result
37653765

37663766

3767+
def test_setitem_w_timestamp_none():
3768+
b_df = bpd.DataFrame({'rowindex': [1, 2, 3]})
3769+
b_df['temp_timestamp'] = pd.Timestamp(ts_input=None, unit="us", tz="utc")
3770+
assert b_df['temp_timestamp'].dtype == "timestamp[us][pyarrow]"
3771+
3772+
37673773
def test_loc_setitem_bool_series_scalar_new_col(scalars_dfs):
37683774
scalars_df, scalars_pandas_df = scalars_dfs
37693775
bf_df = scalars_df.copy()
@@ -5714,4 +5720,4 @@ def test_agg_with_dict_containing_non_existing_col_raise_key_error(scalars_dfs):
57145720
}
57155721

57165722
with pytest.raises(KeyError):
5717-
bf_df.agg(agg_funcs)
5723+
bf_df.agg(agg_funcs)

0 commit comments

Comments
 (0)