You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2021/08/25 10:09:06 UTC
[GitHub] [arrow-datafusion] francis-du opened a new pull request #942: [Python] - Support show function for DataFrame api of python library
francis-du opened a new pull request #942:
URL: https://github.com/apache/arrow-datafusion/pull/942
# Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
-->
Closes #941
# Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
-->
# What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
-->
Add `show` function for DataFrame api of python library
# Are there any user-facing changes?
<!--
If there are user-facing changes then we may require documentation to be updated before approving the PR.
-->
<!--
If there are any breaking changes to public APIs, please add the `api change` label.
-->
Users can directly print the query results by calling the show function.
```python
import pyarrow as pa
from datafusion import ExecutionContext
ctx = ExecutionContext()
batch = pa.RecordBatch.from_arrays(
[pa.array([1, 2, 3]), pa.array([4, 5, 6])],
names=["a", "b"],
)
df = ctx.create_dataframe([[batch]])
df.show()
```
Result
```
+---+---+
| a | b |
+---+---+
| 1 | 4 |
| 2 | 5 |
| 3 | 6 |
+---+---+
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] houqp merged pull request #942: [Python] - Support show function for DataFrame api of python library
Posted by GitBox <gi...@apache.org>.
houqp merged pull request #942:
URL: https://github.com/apache/arrow-datafusion/pull/942
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-datafusion] andygrove commented on a change in pull request #942: [Python] - Support show function for DataFrame api of python library
Posted by GitBox <gi...@apache.org>.
andygrove commented on a change in pull request #942:
URL: https://github.com/apache/arrow-datafusion/pull/942#discussion_r697431047
##########
File path: python/src/dataframe.rs
##########
@@ -139,6 +140,30 @@ impl DataFrame {
to_py::to_py(&batches)
}
+ /// Print the result, 20 lines by default
+ #[args(num = "20")]
+ fn show(&self, py: Python, num: usize) -> PyResult<()> {
+ let ctx = _ExecutionContext::from(self.ctx_state.clone());
+ let plan = ctx
+ .optimize(&self.limit(num)?.plan)
+ .map_err(|e| -> errors::DataFusionError { e.into() })?;
+ let plan = ctx
+ .create_physical_plan(&plan)
+ .map_err(|e| -> errors::DataFusionError { e.into() })?;
Review comment:
You can chain these together to reduce the error handling code.
```suggestion
let plan = ctx
.optimize(&self.limit(num)?.plan)
.and_then(|plan| ctx.create_physical_plan(&plan))
.map_err(|e| -> errors::DataFusionError { e.into() })?;
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org