From 258a1b49974766662db2ffed3747d5b43b4aff0e Mon Sep 17 00:00:00 2001 From: Ritchie Vink Date: Wed, 1 Mar 2023 15:07:22 +0100 Subject: [PATCH] feat(rust, python): add support for serializing categoricals to json (#7276) --- Cargo.toml | 2 +- py-polars/Cargo.lock | 2 +- py-polars/tests/unit/io/test_json.py | 10 ++++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 974ea3f857e0..1c486184439c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,7 +42,7 @@ package = "arrow2" git = "https://github.com/ritchie46/arrow2" # rev = "7be484eb530805696c1ab79aae809f973d92cd5a" # path = "../arrow2" -branch = "polars_2023-02-22" +branch = "polars_2023-03-01" version = "0.16" default-features = false features = [ diff --git a/py-polars/Cargo.lock b/py-polars/Cargo.lock index e56121681f9d..d835ebff2c7f 100644 --- a/py-polars/Cargo.lock +++ b/py-polars/Cargo.lock @@ -84,7 +84,7 @@ dependencies = [ [[package]] name = "arrow2" version = "0.16.0" -source = "git+https://github.com/ritchie46/arrow2?branch=polars_2023-02-22#bbeb28ac4384930d342ee8b3152de93fc89dca31" +source = "git+https://github.com/ritchie46/arrow2?branch=polars_2023-03-01#db533042a0129ea9ea26eec4c481126f29b6e631" dependencies = [ "ahash", "arrow-format", diff --git a/py-polars/tests/unit/io/test_json.py b/py-polars/tests/unit/io/test_json.py index 01a8973d0a09..432d21758241 100644 --- a/py-polars/tests/unit/io/test_json.py +++ b/py-polars/tests/unit/io/test_json.py @@ -103,3 +103,13 @@ def test_ndjson_nested_utf8_int() -> None: assert pl.read_ndjson(io.StringIO(ndjson)).to_dict(False) == { "Accumulables": [[{"Value": "32395888"}, {"Value": "539454"}]] } + + +def test_write_json_categoricals() -> None: + data = {"column": ["test1", "test2", "test3", "test4"]} + df = pl.DataFrame(data).with_columns(pl.col("column").cast(pl.Categorical)) + + assert ( + df.write_json(row_oriented=True, file=None) + == '[{"column":"test1"},{"column":"test2"},{"column":"test3"},{"column":"test4"}]' + )