mirror of
https://github.com/apache/zeppelin
synced 2026-05-24 09:38:26 +00:00
### What is this PR for? Display Pandas DataFrame using Zeppelin's Table Display system. ### What type of PR is it? Feature ### Todos * [x] fix NPE in logs on empty paragraph execution * [x] matplotlib: refactor `zeppelin_show(plt)` -> `z.show(plt)` * [x] pandas: support `z.show(df)` * [x] update docs ### What is the Jira issue? [ZEPPELIN-1048](https://issues.apache.org/jira/browse/ZEPPELIN-1048) ### How should this be tested? "Zeppelin Tutorial: Python - matplotlib basic" should work, and ```python import pandas as pd rates = pd.read_csv("bank.csv", sep=";") z.show(rates) ``` ### Screenshots (if appropriate)  ### Questions: * Does the licenses files need update? No * Is there breaking changes for older versions? No * Does this needs documentation? Yes Author: Alexander Bezzubov <bzz@apache.org> Closes #1067 from bzz/python/pandas-support and squashes the following commits:3b1ad36[Alexander Bezzubov] Python: update docs to reffer new APIee6668b[Alexander Bezzubov] Python: update docs, add Pandas integration71be418[Alexander Bezzubov] Python: limit 1000 for table display system on DataFrame52e787d[Alexander Bezzubov] Python: pandas DataFrame using Table display systembc91b86[Alexander Bezzubov] Python: skip interpreting empty paragraphsa7248cd[Alexander Bezzubov] Python: draft of pandas support15646a1[Alexander Bezzubov] Python: refactoring to z.show()
57 lines
2.3 KiB
Python
57 lines
2.3 KiB
Python
# Licensed to the Apache Software Foundation (ASF) under one or more
|
|
# contributor license agreements. See the NOTICE file distributed with
|
|
# this work for additional information regarding copyright ownership.
|
|
# The ASF licenses this file to You under the Apache License, Version 2.0
|
|
# (the "License"); you may not use this file except in compliance with
|
|
# the License. You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
from py4j.java_gateway import JavaGateway
|
|
from py4j.java_gateway import java_import, JavaGateway, GatewayClient
|
|
|
|
|
|
client = GatewayClient(port=%PORT%)
|
|
gateway = JavaGateway(client)
|
|
java_import(gateway.jvm, "org.apache.zeppelin.display.Input")
|
|
|
|
|
|
class Py4jZeppelinContext(PyZeppelinContext):
|
|
"""A context impl that uses Py4j to communicate to JVM
|
|
"""
|
|
def __init__(self, zc):
|
|
super(Py4jZeppelinContext, self).__init__(zc)
|
|
self.paramOption = gateway.jvm.org.apache.zeppelin.display.Input.ParamOption
|
|
self.javaList = gateway.jvm.java.util.ArrayList
|
|
self.max_result = 1000 #TODO(bzz): read `zeppelin.python.maxResult` from JVM
|
|
|
|
def input(self, name, defaultValue=""):
|
|
return self.z.getGui().input(name, defaultValue)
|
|
|
|
def select(self, name, options, defaultValue=""):
|
|
javaOptions = gateway.new_array(self.paramOption, len(options))
|
|
i = 0
|
|
for tuple in options:
|
|
javaOptions[i] = self.paramOption(tuple[0], tuple[1])
|
|
i += 1
|
|
return self.z.getGui().select(name, defaultValue, javaOptions)
|
|
|
|
def checkbox(self, name, options, defaultChecked=[]):
|
|
javaOptions = gateway.new_array(self.paramOption, len(options))
|
|
i = 0
|
|
for tuple in options:
|
|
javaOptions[i] = self.paramOption(tuple[0], tuple[1])
|
|
i += 1
|
|
javaDefaultCheck = self.javaList()
|
|
for check in defaultChecked:
|
|
javaDefaultCheck.append(check)
|
|
return self.z.getGui().checkbox(name, javaDefaultCheck, javaOptions)
|
|
|
|
|
|
z = Py4jZeppelinContext(gateway.entry_point)
|