Skip to content

Commit fdf623d

Browse files
authored
Revert "feat: support to cast struct to json (#2067)" (#2072)
This reverts commit b0ff718.
1 parent a63cbae commit fdf623d

File tree

4 files changed

+4
-35
lines changed

4 files changed

+4
-35
lines changed

bigframes/core/compile/ibis_compiler/scalar_op_registry.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,8 +1023,6 @@ def astype_op_impl(x: ibis_types.Value, op: ops.AsTypeOp):
10231023
x, ibis_dtypes.string, safe=op.safe
10241024
)
10251025
return parse_json_in_safe(x_str) if op.safe else parse_json(x_str)
1026-
if x.type().is_struct():
1027-
return to_json_string(typing.cast(ibis_types.StructValue, x))
10281026

10291027
if x.type() == ibis_dtypes.json:
10301028
if to_type == ibis_dtypes.int64:
@@ -2071,7 +2069,7 @@ def json_extract_string_array( # type: ignore[empty-body]
20712069

20722070
@ibis_udf.scalar.builtin(name="to_json_string")
20732071
def to_json_string( # type: ignore[empty-body]
2074-
json_obj,
2072+
json_obj: ibis_dtypes.JSON,
20752073
) -> ibis_dtypes.String:
20762074
"""Convert JSON to STRING."""
20772075

bigframes/dtypes.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -641,9 +641,6 @@ def _dtype_from_string(dtype_string: str) -> typing.Optional[Dtype]:
641641
return BIGFRAMES_STRING_TO_BIGFRAMES[
642642
typing.cast(DtypeString, str(dtype_string))
643643
]
644-
if isinstance(dtype_string, str) and dtype_string.lower() == "json":
645-
return JSON_DTYPE
646-
647644
raise TypeError(
648645
textwrap.dedent(
649646
f"""
@@ -655,9 +652,9 @@ def _dtype_from_string(dtype_string: str) -> typing.Optional[Dtype]:
655652
The following pandas.ExtensionDtype are supported:
656653
pandas.BooleanDtype(), pandas.Float64Dtype(),
657654
pandas.Int64Dtype(), pandas.StringDtype(storage="pyarrow"),
658-
pandas.ArrowDtype(pa.date32()), pandas.ArrowDtype(pa.time64("us")),
659-
pandas.ArrowDtype(pa.timestamp("us")),
660-
pandas.ArrowDtype(pa.timestamp("us", tz="UTC")).
655+
pd.ArrowDtype(pa.date32()), pd.ArrowDtype(pa.time64("us")),
656+
pd.ArrowDtype(pa.timestamp("us")),
657+
pd.ArrowDtype(pa.timestamp("us", tz="UTC")).
661658
{constants.FEEDBACK_LINK}
662659
"""
663660
)

bigframes/operations/generic_ops.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,6 @@ def _valid_cast(src: dtypes.Dtype, dst: dtypes.Dtype):
324324
if not _valid_cast(src_dtype, dst_dtype):
325325
return False
326326
return True
327-
if dtypes.is_struct_like(src) and dst == dtypes.JSON_DTYPE:
328-
return True
329327

330328
return _valid_scalar_cast(src, dst)
331329

tests/system/small/test_series.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3866,30 +3866,6 @@ def test_string_astype_timestamp():
38663866
pd.testing.assert_series_equal(bf_result, pd_result, check_index_type=False)
38673867

38683868

3869-
def test_struct_astype_json():
3870-
"""See internal issue 444196993."""
3871-
s = series.Series(
3872-
[
3873-
{"version": 1, "project": "pandas"},
3874-
{"version": 2, "project": "numpy"},
3875-
]
3876-
)
3877-
assert dtypes.is_struct_like(s.dtype)
3878-
3879-
expected = series.Series(s, dtype=dtypes.JSON_DTYPE)
3880-
assert expected.dtype == dtypes.JSON_DTYPE
3881-
3882-
result = s.astype("json")
3883-
pd.testing.assert_series_equal(
3884-
result.to_pandas(), expected.to_pandas(), check_index_type=False
3885-
)
3886-
3887-
result = s.astype(dtypes.JSON_DTYPE)
3888-
pd.testing.assert_series_equal(
3889-
result.to_pandas(), expected.to_pandas(), check_index_type=False
3890-
)
3891-
3892-
38933869
def test_timestamp_astype_string():
38943870
bf_series = series.Series(
38953871
[

0 commit comments

Comments
 (0)