8000 fix: support setitem with NaTType by chelsea-lin · Pull Request #1928 · googleapis/python-bigquery-dataframes · GitHub
[go: up one dir, main page]

Skip to content
Closed
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
5 changes: 0 additions & 5 deletions bigframes/core/array_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import warnings

import google.cloud.bigquery
import pandas
import pyarrow as pa

import bigframes.core.expression as ex
Expand Down Expand Up @@ -324,10 +323,6 @@ def create_constant(
value: typing.Any,
dtype: typing.Optional[bigframes.dtypes.Dtype],
) -> Tuple[ArrayValue, str]:
if pandas.isna(value):
# Need to assign a data type when value is NaN.
dtype = dtype or bigframes.dtypes.DEFAULT_DTYPE

return self.project_to_id(ex.const(value, dtype))

def select_columns(
Expand Down
4 changes: 2 additions & 2 deletions bigframes/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,14 +674,14 @@ def infer_literal_type(literal) -> typing.Optional[Dtype]:
pa.field(key, field_type, nullable=(not pa.types.is_list(field_type)))
)
return pd.ArrowDtype(pa.struct(fields))
if pd.isna(literal):
return None # Null value without a definite type
# Make sure to check datetime before date as datetimes are also dates
if isinstance(literal, (datetime.datetime, pd.Timestamp)):
if literal.tzinfo is not None:
return TIMESTAMP_DTYPE
else:
return DATETIME_DTYPE
if pd.isna(literal):
return None # Null value without a definite type
from_python_type = _infer_dtype_from_python_type(type(literal))
if from_python_type is not None:
return from_python_type
Expand Down
6 changes: 6 additions & 0 deletions tests/system/small/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -3764,6 +3764,12 @@ def test_at_no_duplicate(scalars_df_index, scalars_pandas_df_index):
assert bf_result == pd_result


def test_setitem_w_timestamp_none():
b_df = bpd.DataFrame({"rowindex": [1, 2, 3]})
b_df["temp_timestamp"] = pd.Timestamp(ts_input=pd.NaT, unit="us", tz="utc") # type: ignore
assert b_df["temp_timestamp"].dtype == "timestamp[us][pyarrow]"


def test_loc_setitem_bool_series_scalar_new_col(scalars_dfs):
scalars_df, scalars_pandas_df = scalars_dfs
bf_df = scalars_df.copy()
Expand Down
0