-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MongoDB Full: Polars'
read_ndjson
doesn't load MongoDB JSON data well
Use `fsspec` and `orjson` instead.
- Loading branch information
Showing
5 changed files
with
37 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import orjsonl | ||
from fsspec import filesystem | ||
from upath import UPath | ||
|
||
|
||
def read_json(url: str): | ||
""" | ||
Read JSON file from anywhere. | ||
TODO: Does the resource need to be closed? How? | ||
""" | ||
p = UPath(url) | ||
fs = filesystem(p.protocol, **p.storage_options) # equivalent to p.fs | ||
fp = fs.open(p.path) | ||
data = orjsonl.stream(fp) | ||
return data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters