This is an automated email from the ASF dual-hosted git repository. jongyoul pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/zeppelin.git
The following commit(s) were added to refs/heads/master by this push: new 4352a10ab9 [ZEPPELIN-5875] Add: z.show works with subtypes of DataFrame (#4683) 4352a10ab9 is described below commit 4352a10ab95af975e08f3019ca07027b7070e62e Author: Matthias Koch <23187557+matthias-k...@users.noreply.github.com> AuthorDate: Wed Nov 8 03:47:37 2023 +0100 [ZEPPELIN-5875] Add: z.show works with subtypes of DataFrame (#4683) --- python/src/main/resources/python/zeppelin_context.py | 2 +- .../zeppelin/python/BasePythonInterpreterTest.java | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/python/src/main/resources/python/zeppelin_context.py b/python/src/main/resources/python/zeppelin_context.py index de3807d09e..8223966d40 100644 --- a/python/src/main/resources/python/zeppelin_context.py +++ b/python/src/main/resources/python/zeppelin_context.py @@ -179,7 +179,7 @@ class PyZeppelinContext(object): def show(self, p, **kwargs): if hasattr(p, '__name__') and p.__name__ == "matplotlib.pyplot": self.show_matplotlib(p, **kwargs) - elif type(p).__name__ == "DataFrame": # does not play well with sub-classes + elif any(t.__name__ == 'DataFrame' for t in type(p).mro()): # `isinstance(p, DataFrame)` would req `import pandas.core.frame.DataFrame` # and so a dependency on pandas self.show_dataframe(p, **kwargs) diff --git a/python/src/test/java/org/apache/zeppelin/python/BasePythonInterpreterTest.java b/python/src/test/java/org/apache/zeppelin/python/BasePythonInterpreterTest.java index 7469fdd474..ecb903280b 100644 --- a/python/src/test/java/org/apache/zeppelin/python/BasePythonInterpreterTest.java +++ b/python/src/test/java/org/apache/zeppelin/python/BasePythonInterpreterTest.java @@ -311,6 +311,22 @@ public abstract class BasePythonInterpreterTest extends ConcurrentTestCase { assertEquals(InterpreterResult.Type.TABLE, interpreterResultMessages.get(0).getType()); assertEquals("id\tname\n1\ta a\n2\tb b\n3\tc c\n", interpreterResultMessages.get(0).getData()); + // Pandas DataFrame with sub type + context = getInterpreterContext(); + result = interpreter.interpret("import pandas as pd\n" + + "class ExtendedDataFrame(pd.DataFrame):\n" + + " pass\n" + + "df = ExtendedDataFrame({'id':[1,2,3], 'name':['a\ta','b\\nb','c\\r\\nc']})\n" + + "z.show(df)", + context); + assertEquals(InterpreterResult.Code.SUCCESS, result.code(), + context.out.toInterpreterResultMessage().toString()); + interpreterResultMessages = context.out.toInterpreterResultMessage(); + assertEquals(1, interpreterResultMessages.size()); + assertEquals(InterpreterResult.Type.TABLE, interpreterResultMessages.get(0).getType()); + assertEquals("id\tname\n1\ta a\n2\tb b\n3\tc c\n", interpreterResultMessages.get(0).getData()); + + // Pandas DataFrame limited to three results context = getInterpreterContext(); result = interpreter.interpret("import pandas as pd\n" + "df = pd.DataFrame({'id':[1,2,3,4], 'name':['a','b','c', 'd']})\nz.show(df)", context);