You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "Eason0729 (via GitHub)" <gi...@apache.org> on 2024/09/21 05:03:51 UTC
[PR] docs: :memo: Add expected answers to `DataFrame` method examples [datafusion]
Eason0729 opened a new pull request, #12564:
URL: https://github.com/apache/datafusion/pull/12564
## 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 #12527.
## 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.
-->
## Are these changes tested?
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
-->
## 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.
-->
--
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@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] docs: :memo: Add expected answers to `DataFrame` method examples [datafusion]
Posted by "Eason0729 (via GitHub)" <gi...@apache.org>.
Eason0729 commented on code in PR #12564:
URL: https://github.com/apache/datafusion/pull/12564#discussion_r1769600749
##########
datafusion/core/src/dataframe/mod.rs:
##########
@@ -225,7 +225,12 @@ impl DataFrame {
/// # async fn main() -> Result<()> {
/// let ctx = SessionContext::new();
/// let df = ctx.read_csv("tests/data/example.csv", CsvReadOptions::new()).await?;
- /// let df = df.select_columns(&["a", "b"])?;
+ /// df.select_columns(&["a", "b"])?.show().await?;
Review Comment:
My original thought is to simplify large long column on doctest(less readable), like this: https://github.com/Eason0729/datafusion/blob/4dd44c5a2b0d9810d7e9163689afab227c58d542/datafusion/core/src/dataframe/mod.rs#L734
Therefore, I simplify example_long.csv in the next commit to the point which is just enough to showcase most method on dataframe.
--
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@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] docs: :memo: Add expected answers to `DataFrame` method examples [datafusion]
Posted by "comphead (via GitHub)" <gi...@apache.org>.
comphead commented on PR #12564:
URL: https://github.com/apache/datafusion/pull/12564#issuecomment-2365265416
Thanks @Eason0729 for your contribution.
I'm feeling we need to have something to create DF from rows rather in addition to creating DF from data files.
Example can be
```
let schema =
DataFrame::from(schema, data)
```
Underneath the method can call `ctx.read_batch(record_batch)`. The batch can be created with `RecordBatch::try_from_iter`
--
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@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] docs: :memo: Add expected answers to `DataFrame` method examples [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #12564:
URL: https://github.com/apache/datafusion/pull/12564#discussion_r1769534737
##########
datafusion/core/src/dataframe/mod.rs:
##########
@@ -225,7 +225,12 @@ impl DataFrame {
/// # async fn main() -> Result<()> {
/// let ctx = SessionContext::new();
/// let df = ctx.read_csv("tests/data/example.csv", CsvReadOptions::new()).await?;
- /// let df = df.select_columns(&["a", "b"])?;
+ /// df.select_columns(&["a", "b"])?.show().await?;
Review Comment:
What would you think about using [`assert_batches_eq` ](https://docs.rs/datafusion/latest/datafusion/macro.assert_batches_eq.html)instead so that the output is automatically checked as part of the doc tests rather than relying on us manually keeping it up to date?
It is of similar readability I think. Here is an example:
https://github.com/apache/datafusion/blob/d9cb6e677ec437a9c6ff2cc0900f902804da39bb/datafusion/core/tests/sql/select.rs#L27-L49
--
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@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] docs: :memo: Add expected answers to `DataFrame` method examples [datafusion]
Posted by "Eason0729 (via GitHub)" <gi...@apache.org>.
Eason0729 commented on code in PR #12564:
URL: https://github.com/apache/datafusion/pull/12564#discussion_r1769601086
##########
datafusion/core/src/dataframe/mod.rs:
##########
@@ -225,7 +225,12 @@ impl DataFrame {
/// # async fn main() -> Result<()> {
/// let ctx = SessionContext::new();
/// let df = ctx.read_csv("tests/data/example.csv", CsvReadOptions::new()).await?;
- /// let df = df.select_columns(&["a", "b"])?;
+ /// df.select_columns(&["a", "b"])?.show().await?;
Review Comment:
But the expect behavior on `describe` method is more complex, which might require dedicated csv, so I decided to leave as it is.
--
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@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] docs: :memo: Add expected answers to `DataFrame` method examples [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #12564:
URL: https://github.com/apache/datafusion/pull/12564#issuecomment-2368913123
📝
--
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@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] docs: :memo: Add expected answers to `DataFrame` method examples [datafusion]
Posted by "comphead (via GitHub)" <gi...@apache.org>.
comphead merged PR #12564:
URL: https://github.com/apache/datafusion/pull/12564
--
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@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] docs: :memo: Add expected answers to `DataFrame` method examples [datafusion]
Posted by "comphead (via GitHub)" <gi...@apache.org>.
comphead commented on code in PR #12564:
URL: https://github.com/apache/datafusion/pull/12564#discussion_r1769621368
##########
datafusion/core/src/dataframe/mod.rs:
##########
@@ -184,7 +184,7 @@ impl DataFrame {
}
/// Creates logical expression from a SQL query text.
- /// The expression is created and processed againt the current schema.
+ /// The expression is created and processed against the current schema.
Review Comment:
👍
--
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@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] docs: :memo: Add expected answers to `DataFrame` method examples [datafusion]
Posted by "comphead (via GitHub)" <gi...@apache.org>.
comphead commented on code in PR #12564:
URL: https://github.com/apache/datafusion/pull/12564#discussion_r1769622225
##########
datafusion/core/src/dataframe/mod.rs:
##########
@@ -344,11 +376,26 @@ impl DataFrame {
/// ```
/// # use datafusion::prelude::*;
/// # use datafusion::error::Result;
+ /// # use datafusion_common::assert_batches_sorted_eq;
/// # #[tokio::main]
/// # async fn main() -> Result<()> {
/// let ctx = SessionContext::new();
/// let df = ctx.read_json("tests/data/unnest.json", NdJsonReadOptions::default()).await?;
+ /// // expend into multiple columns if it's json array, flatten field name if it's nested structure
Review Comment:
```suggestion
/// // expand into multiple columns if it's json array, flatten field name if it's nested structure
```
--
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@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] docs: :memo: Add expected answers to `DataFrame` method examples [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #12564:
URL: https://github.com/apache/datafusion/pull/12564#issuecomment-2366737519
> I'm feeling we need to have something to create DF from rows rather in addition to creating DF from data files.
This seems reasonable to me -- perhaps you can file a ticket to track the idea and we can as our resident DataFrame experts like @timsaucer and @Omega359
--
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@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] docs: :memo: Add expected answers to `DataFrame` method examples [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #12564:
URL: https://github.com/apache/datafusion/pull/12564#issuecomment-2366737614
Thanks again @Eason0729
--
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@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org