Skip to content

Commit

Permalink
python to_json, run if no arg is given
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Sep 12, 2021
1 parent 677d69b commit cacd13e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion py-polars/polars/eager/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ def to_json(
to_string
Ignore file argument and return a string.
"""
if to_string:
if to_string or file is None:
file = BytesIO()
self._df.to_json(file, pretty)
file.seek(0)
Expand Down
8 changes: 8 additions & 0 deletions py-polars/tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,11 @@ def test_copy():
a = pl.Series("a", [1, 2])
copy.copy(a).series_equal(a, True)
copy.deepcopy(a).series_equal(a, True)


def test_to_json():
# tests if it runs if no arg given
df = pl.DataFrame({"a": [1, 2, 3]})
assert (
df.to_json() == '{"columns":[{"name":"a","datatype":"Int64","values":[1,2,3]}]}'
)

0 comments on commit cacd13e

Please sign in to comment.