-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from e2b-dev/beta-df
Extract data from DataFrames
- Loading branch information
Showing
12 changed files
with
90 additions
and
8 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
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,10 @@ | ||
import { expect } from 'vitest' | ||
|
||
import { sandboxTest } from './setup' | ||
|
||
sandboxTest('get data', async ({ sandbox }) => { | ||
const execution = await sandbox.notebook.execCell('pd.DataFrame({"a": [1, 2, 3]})') | ||
|
||
const result = execution.results[0] | ||
expect(result.data).toBeDefined() | ||
}) |
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,16 @@ | ||
from e2b_code_interpreter.code_interpreter_async import AsyncCodeInterpreter | ||
|
||
|
||
async def test_data(async_sandbox: AsyncCodeInterpreter): | ||
# plot random graph | ||
result = await async_sandbox.notebook.exec_cell( | ||
""" | ||
pd.DataFrame({"a": [1, 2, 3]}) | ||
""" | ||
) | ||
|
||
# there's your image | ||
data = result.results[0] | ||
assert data.data | ||
assert "a" in data.data | ||
assert len(data.data["a"]) == 3 |
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,16 @@ | ||
from e2b_code_interpreter.code_interpreter_sync import CodeInterpreter | ||
|
||
|
||
def test_data(sandbox: CodeInterpreter): | ||
# plot random graph | ||
result = sandbox.notebook.exec_cell( | ||
""" | ||
pd.DataFrame({"a": [1, 2, 3]}) | ||
""" | ||
) | ||
|
||
# there's your image | ||
data = result.results[0] | ||
assert data.data | ||
assert "a" in data.data | ||
assert len(data.data["a"]) == 3 |
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,18 @@ | ||
import pandas as pd | ||
|
||
|
||
def _repr_mimebundle_(self, include=None, exclude=None): | ||
data = { | ||
'text/html': self.to_html(), | ||
'text/plain': self.to_string(), | ||
'e2b/df': self.to_dict(orient='list'), | ||
} | ||
|
||
if include: | ||
data = {k: v for (k, v) in data.items() if k in include} | ||
if exclude: | ||
data = {k: v for (k, v) in data.items() if k not in exclude} | ||
return data | ||
|
||
|
||
setattr(pd.DataFrame, '_repr_mimebundle_', _repr_mimebundle_) |
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