https://opendal.apache.org/ logo
OpenDAL + pandas/polars
# general
a
Hi, I just came across OpenDAL. Quick question, how would OpenDAL interoperate or work with pandas/polars? Let say using python bindings, read the file from s3 and import it to pandas/polars, is is possible? I haven't found any docs on that
x
It must be possible!
And we do lack of python docs and this is what we want to improve this year.
There are many possible ways: - opendal will build native fsspec integration via rust - opendal python binding can implement fsspec - opendal provides object_store_opendal integration which can play with polars directly.
Which way do you prefer? I'm willing to figure it our and provide some docs.
a
Copy code
import opendal

op = opendal.Operator("s3", root="/tmp", bucket="your_bucket_name", region="your_region")
op.write("test.txt", b"Hello World")
print(op.read("test.txt"))
print(op.stat("test.txt").content_length)
Here, I see that the operator reads the
test.txt
from s3 using
op.read("test.txt")
, so how do I consume this
op.read("test.txt")
to pandas/polars, prefering polars?
x
Not familiar with polars, let me check it out first.
The result returned by
op.read()
is
Bytes
, you can pass it to polars's
read_xxx
API like
polars.read_json(bs)
a
ohhh, I get that
x
polars.read_json()
also accept file like object, so you can also do
polars.read_json(op.open(path))
a
ah thanks, definitely try that tonight
x
opendal's python binding is at it's very early stage
Welcome to provide your feedbacks to help us improve it.
a
How could you check that so fast?
Install and directly check it through source code?
x
Are your talking about polars's API?
a
Yeah kinds of
a
Ah I get that 😂
I checked scan_json which is not accepted bytes as input
Anw, thanks for supporting.
Just come across OpenDAL through a discussion on X
x
Aha, got it. scan_xxx API is used to list json files from given pathes.
Would you like to point me with the link? I'm interested!
here you go
x
Thanks!
a
I think you should contribute to that benchmarks or maybe introduce some information on OpenDAL, which helps spreading OpenDAL to communities
x
Thanks for the advices!
a
The OP mentioned opendal but hasn’t included it in benchmarks.
I guess it’s due to the lack of documentation or examples on python bindings (e.g. inter-opt with pandas, or polars)
x
Yep!
Our primary focus is on our Rust core, and we will improve the Python Binding this year.
documentation and examples are good start.
b
I think one of the workarounds I had to implement if to set a method
readable
which returns
True
to make it play nicely with Python's
io.IOBase
x
Oh, opendal.File doesn't have this?
b
I don't think so no, happy to help
x
Welcome!
b
No problem, will make an issue later today with some examples
a
it looks like python bindings of OpenDAL hasn't supported read globb patterns or multiple files right? @Xuanwo
when I try OpenDAL, it successfully read one file
Copy code
python
def ingest_log():
    dotenv.load_dotenv()
    access_key_id = os.getenv("AWS_ACCESS_KEY_ID")
    secret_access_key = os.getenv("AWS_SECRET_ACCESS_KEY")
    region = os.getenv("AWS_REGION")
    op = opendal.Operator(
        "s3",
        root='/log_content/',
        bucket='data',
        region=region,
        endpoint='http://127.0.0.1:9000',
        access_key_id=access_key_id,
        secret_access_key=secret_access_key,
    )
    bs = op.read(["20220401.json", "20220402.json"]) #this fails
    return bs
x
Yes, read only accept a single path.
Having an API like:
Copy code
python
bs = op.read(["20220401.json", "20220402.json"])
is strange.
It's hard to predict what's the type of
bs
.
a
I think
op.read
should support read a list of str of list of path or glob patterns
ohh, one more things, to get Polars read
bs
, I have to get it to bytes, i.e.
bs.tobytes
x
I don’t like this idea. opendal already have list to read a dir.
We have a plan to support list a glob pattern.
a
I think this results better
sorry, forget to press enter 😂 I think I should phrase my question as * "How should I fetch a list of json/csv/parquest using OpenDAL and consume it to pandas/polars?"*
x
Use
list
to fetch a list of file paths, and use
read
to get conten the file, and than fed into polars.
I'm still find more native ways to make
scan_xxx
works with opendal.
a
lenme try it later today, currently wrangling with pyarrow
b
I filed an issue here: https://github.com/apache/opendal/issues/4363 I also noticed this related issue: https://github.com/apache/opendal/issues/4270 sorry for the delay
x
Thanks!
2 Views