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

Support with_projection and with_columns in ipc and parquet reader in eager mode #1751

Merged

Conversation

illumination-k
Copy link
Contributor

Support with_projection and with_columns in IPC and parquet reader to select columns in eager mode.

related to #1569

@ritchie46
Copy link
Member

Looks very good @illumination-k 👍

Do you think you can also expose it in the python API? If you want, I can do it as well.

@@ -161,6 +164,9 @@ where
let i = schema.index_of(column)?;
prj.push(i)
}

// Ipc reader panics if the projection is not in increasing order, so sorting is the safer way.
prj.sort();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, we can remove duplicates, but It seems that it would be more helpful to return an error if there is a duplicate.

It's not good to get an error in select C, B, but wouldn't it be better to get an error in select B, B?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer returning an error indeed. The API expects unique columns.

let schema = metadata.schema();

if let Some(cols) = self.columns {
let mut prj = vec![];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I plan to use it with projections of 100k columns

let mut prj = Vec::with_capacity(cols.len());

@illumination-k
Copy link
Contributor Author

Looks very good @illumination-k 👍

Do you think you can also expose it in the python API? If you want, I can do it as well.

I don't understand much about the python API, but can I just rewrite the following part?

#[staticmethod]
#[cfg(feature = "parquet")]
pub fn read_parquet(py_f: PyObject, stop_after_n_rows: Option<usize>) -> PyResult<Self> {
use EitherRustPythonFile::*;
let result = match get_either_file(py_f, false)? {
Py(f) => {
let buf = f.as_buffer();
ParquetReader::new(buf)
.with_stop_after_n_rows(stop_after_n_rows)
.finish()
}
Rust(f) => ParquetReader::new(f)
.with_stop_after_n_rows(stop_after_n_rows)
.finish(),
};
let df = result.map_err(PyPolarsEr::from)?;
Ok(PyDataFrame::new(df))
}
#[staticmethod]
#[cfg(feature = "ipc")]
pub fn read_ipc(py_f: PyObject) -> PyResult<Self> {
let file = get_file_like(py_f, false)?;
let df = IpcReader::new(file).finish().map_err(PyPolarsEr::from)?;
Ok(PyDataFrame::new(df))
}

def read_parquet(

def read_ipc(file: Union[str, BinaryIO]) -> "DataFrame":

@illumination-k
Copy link
Contributor Author

@ritchie46
I successfully ran pl.read_ipc and pl.read_parquet without pyarrow and added test. In my opinion, some development instructions for Python would have been very much appreciated, eg., how to test, how to format, how to set up virtualenv etc...

py-polars/polars/io.py Outdated Show resolved Hide resolved
@ritchie46
Copy link
Member

@ritchie46 I successfully ran pl.read_ipc and pl.read_parquet without pyarrow and added test. In my opinion, some development instructions for Python would have been very much appreciated, eg., how to test, how to format, how to set up virtualenv etc...

Thanks. It looks solid. Great work!

Maybe you could add what you missed in the cobtrubution guide?

@illumination-k
Copy link
Contributor Author

Oh I'm really sorry, I missed the last part... It is sufficient for me.

@ritchie46
Copy link
Member

Very nice work @illumination-k. Thanks a lot!

@ritchie46 ritchie46 merged commit a40061b into pola-rs:master Nov 13, 2021
@illumination-k illumination-k deleted the feature/read-with-column-names branch November 13, 2021 07:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants