Skip to content

Commit

Permalink
feat(rust, python): add support for serializing categoricals to json (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 authored Mar 1, 2023
1 parent 21a3881 commit 258a1b4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
2 changes: 1 addition & 1 deletion py-polars/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions py-polars/tests/unit/io/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}]'
)

0 comments on commit 258a1b4

Please sign in to comment.