Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin for pandas dataframes and JS API/UI support #1942

Merged
merged 6 commits into from
Apr 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions Integrations/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ def normalize_version(ver):
keywords='Deephaven Development',
packages=find_packages(exclude=['docs', 'test']),
install_requires=['deephaven-jpy=={}'.format(__normalized_version__),
'numpy', 'dill>=0.2.8', 'wrapt', 'pandas', 'numba;python_version>"3.0"',
'enum34;python_version<"3.4"'],
'numpy',
'dill>=0.2.8',
'wrapt',
'pandas',
'numba;python_version>"3.0"',
'enum34;python_version<"3.4"',
],
)
7 changes: 7 additions & 0 deletions py/server/deephaven/pandasplugin/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from deephaven.plugin import Registration
from . import pandas_as_table

class PandasPluginRegistration(Registration):
@classmethod
def register_into(clscls, callback: Registration.Callback) -> None:
callback.register(pandas_as_table.PandasDataFrameSerializer)
18 changes: 18 additions & 0 deletions py/server/deephaven/pandasplugin/pandas_as_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from deephaven.pandas import to_table
from deephaven.plugin.object import Exporter, ObjectType
from pandas import DataFrame

NAME = "pandas.DataFrame"


class PandasDataFrameSerializer(ObjectType):
@property
def name(self) -> str:
return NAME

def is_type(self, object) -> bool:
return isinstance(object, DataFrame)

def to_bytes(self, exporter: Exporter, data_frame: DataFrame):
exporter.reference(to_table(data_frame))
return b''
13 changes: 11 additions & 2 deletions py/server/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ def normalize_version(version):
],
keywords='Deephaven Development',
install_requires=['deephaven-jpy=={}'.format(__normalized_version__),
'numpy', 'dill>=0.2.8', 'wrapt', 'pandas', 'numba;python_version>"3.0"',
'enum34;python_version<"3.4"'],
'deephaven-plugin',
'numpy',
'dill>=0.2.8',
'wrapt',
'pandas',
'numba;python_version>"3.0"',
'enum34;python_version<"3.4"'
],
entry_points={
'deephaven.plugin': ['registration_cls = deephaven.pandasplugin:PandasPluginRegistration']
},
)
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public Promise<JsFigure> getFigure(String name) {
return getVariableDefinition(name, JsVariableChanges.FIGURE).then(connection::getFigure);
}

public Promise<Object> getObject(JsPropertyMap<Object> definitionObject) {
public Promise<?> getObject(JsPropertyMap<Object> definitionObject) {
if (definitionObject instanceof JsVariableDefinition) {
return connection.getObject((JsVariableDefinition) definitionObject);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -680,31 +680,16 @@ public Promise<JsTable> getTable(JsVariableDefinition varDef, @Nullable Boolean
});
}

public Promise<JsTable> getPandas(JsVariableDefinition varDef) {
return whenServerReady("get a pandas table").then(serve -> {
JsLog.debug("innerGetPandasTable", varDef.getTitle(), " started");
return newState(info,
(c, cts, metadata) -> {
JsLog.debug("performing fetch for ", varDef.getTitle(), " / ", cts,
" (" + LazyString.of(cts::getHandle), ")");
throw new UnsupportedOperationException("getPandas");

}, "fetch pandas table " + varDef.getTitle()).then(cts -> {
JsLog.debug("innerGetPandasTable", varDef.getTitle(), " succeeded ", cts);
JsTable table = new JsTable(this, cts);
return Promise.resolve(table);
});
});
}

@SuppressWarnings({"unchecked", "rawtypes"})
public Promise<Object> getObject(JsVariableDefinition definition) {
if (definition.getType().equals(JsVariableChanges.TABLE)) {
return (Promise) getTable(definition, null);
} else if (definition.getType().equals(JsVariableChanges.FIGURE)) {
return (Promise) getFigure(definition);
public Promise<?> getObject(JsVariableDefinition definition) {
if (JsVariableChanges.TABLE.equals(definition.getType())) {
return getTable(definition, null);
} else if (JsVariableChanges.FIGURE.equals(definition.getType())) {
return getFigure(definition);
} else if (JsVariableChanges.PANDAS.equals(definition.getType())) {
return getWidget(definition)
.then(widget -> widget.getExportedObjects()[0].fetch());
} else {
return (Promise) getWidget(definition);
return getWidget(definition);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class JsVariableChanges {
TABLEMAP = "TableMap",
FIGURE = "Figure",
OTHERWIDGET = "OtherWidget",
PANDAS = "Pandas";
PANDAS = "pandas.DataFrame";

private final JsVariableDefinition[] created;
private final JsVariableDefinition[] updated;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public String getType() {
}

@JsMethod
public Promise<Object> fetch() {
public Promise<?> fetch() {
if (getType().equals(JsVariableChanges.TABLE)) {
return Callbacks.<ExportedTableCreationResponse, Object>grpcUnaryPromise(c -> {
connection.tableServiceClient().getExportedTableCreationResponse(ticket.getTicket(),
Expand Down