Skip to content

Commit

Permalink
fixup! logic
Browse files Browse the repository at this point in the history
  • Loading branch information
stinodego committed May 28, 2024
1 parent e27c80d commit d16f4df
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions py-polars/polars/dataframe/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2340,24 +2340,24 @@ def write_json(
version="0.20.31",
)

def serialize_to_string(*, pretty: bool, row_oriented: bool) -> str:
def write_json_to_string(*, pretty: bool, row_oriented: bool) -> str:
with BytesIO() as buf:
self._df.write_json_old(buf, pretty=pretty, row_oriented=row_oriented)
json_bytes = buf.getvalue()
return json_bytes.decode("utf8")

if file is None:
return serialize_to_string(pretty=pretty, row_oriented=row_oriented)
return write_json_to_string(pretty=pretty, row_oriented=row_oriented)
elif isinstance(file, StringIO):
json_str = serialize_to_string(pretty=pretty, row_oriented=row_oriented)
json_str = write_json_to_string(pretty=pretty, row_oriented=row_oriented)
file.write(json_str)
return None
elif isinstance(file, (str, Path)):
file = normalize_filepath(file)
self._df.serialize(file, pretty=pretty, row_oriented=row_oriented)
self._df.write_json_old(file, pretty=pretty, row_oriented=row_oriented)
return None
else:
self._df.serialize(file, pretty=pretty, row_oriented=row_oriented)
self._df.write_json_old(file, pretty=pretty, row_oriented=row_oriented)
return None

@overload
Expand Down

0 comments on commit d16f4df

Please sign in to comment.