-
Notifications
You must be signed in to change notification settings - Fork 154
Arrow read support (read directly as pyarrow.Table or polars.DataFrame)
#2776
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -385,7 +385,7 @@ def _set_allow_arrow_input(self, allow_arrow_input: bool = True): | |
|
|
||
| def _set_output_format_for_pipeline_tests(self, output_format): | ||
| self.set_output_format(output_format) | ||
| if output_format == OutputFormat.EXPERIMENTAL_ARROW: | ||
| if output_format == OutputFormat.PYARROW: | ||
| self._test_convert_arrow_back_to_pandas = True | ||
|
|
||
| @classmethod | ||
|
|
@@ -1284,21 +1284,17 @@ def batch_read( | |
| For more information see the documentation for the QueryBuilder class. | ||
| i-th entry corresponds to i-th element of `symbols`. | ||
| arrow_string_format_default: Optional[Union[ArrowOutputStringFormat, "pa.DataType"]], default=None | ||
| Controls the default string format used for `ARROW` or `POLARS` output format. | ||
| See documentation of `ArrowOutputStringFormat` for more information on the different options. | ||
| It serves as the default for the entire batch. | ||
| arrow_string_format_per_column: Optional[Dict[str, Union[ArrowOutputStringFormat, "pa.DataType"]]], default=None, | ||
| Controls the string format per column used for `ARROW` or `POLARS` output format. | ||
| See documentation of `ArrowOutputStringFormat` for more information on the different options. | ||
| It is applied to all symbols which don't have a `per_symbol_arrow_string_format_per_column` set. | ||
| per_symbol_arrow_string_format_default: Optional[List[Optional[Union[ArrowOutputStringFormat, "pa.DataType"]]]], default=None, | ||
| Controls the string format per column used for `ARROW` or `POLARS` output format. | ||
| See documentation of `ArrowOutputStringFormat` for more information on the different options. | ||
| It serves as the default per symbol. It overrides the global `arrow_string_format_default` setting | ||
| per_symbol_arrow_string_format_per_column: Optional[List[Optional[Dict[str, Union[ArrowOutputStringFormat, "pa.DataType"]]]]], default=None, | ||
| Controls the string format per column used for `ARROW` or `POLARS` output format. | ||
| See documentation of `ArrowOutputStringFormat` for more information on the different options. | ||
| It defines the setting per symbol and per column. It overrides all other string format settings. | ||
| String column format when using `PYARROW` or `POLARS` output formats. Serves as the default for the entire batch. | ||
| See `ArrowOutputStringFormat` documentation for details on available string formats. | ||
| arrow_string_format_per_column: Optional[Dict[str, Union[ArrowOutputStringFormat, "pa.DataType"]]], default=None | ||
| Per-column overrides for `arrow_string_format_default`. Keys are column names. | ||
| Applied to all symbols without a `per_symbol_arrow_string_format_per_column` set. | ||
| per_symbol_arrow_string_format_default: Optional[List[Optional[Union[ArrowOutputStringFormat, "pa.DataType"]]]], default=None | ||
| Per-symbol override for `arrow_string_format_default`. Overrides the batch-level default. | ||
| i-th entry corresponds to i-th element of `symbols`. | ||
| per_symbol_arrow_string_format_per_column: Optional[List[Optional[Dict[str, Union[ArrowOutputStringFormat, "pa.DataType"]]]]], default=None | ||
| Per-symbol, per-column overrides. Takes precedence over all other string format settings. | ||
| i-th entry corresponds to i-th element of `symbols`. | ||
alexowens90 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| Examples | ||
| -------- | ||
|
|
@@ -2159,12 +2155,13 @@ def _get_read_options_and_output_format( | |
| proto_cfg, | ||
| global_default=ArrowOutputStringFormat.LARGE_STRING, | ||
| **kwargs, | ||
| ) | ||
| ), | ||
| output_format, | ||
| ) | ||
| ) | ||
| read_options.set_arrow_output_per_column_string_format( | ||
| { | ||
| key: arrow_output_string_format_to_internal(value) | ||
| key: arrow_output_string_format_to_internal(value, output_format) | ||
| for key, value in resolve_defaults( | ||
| "arrow_string_format_per_column", proto_cfg, global_default={}, **kwargs | ||
| ).items() | ||
|
|
@@ -2728,8 +2725,8 @@ def _adapt_frame_data(self, frame_data, norm, output_format): | |
| ) | ||
| if self._test_convert_arrow_back_to_pandas: | ||
| data = convert_arrow_to_pandas_for_tests(data) | ||
| if output_format.lower() == OutputFormat.EXPERIMENTAL_POLARS.lower(): | ||
| data = pl.from_arrow(data) | ||
| if output_format.lower() == OutputFormat.POLARS.lower(): | ||
| data = pl.from_arrow(data, rechunk=False) | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This It is done to get better performance on read (rechunking requires memory copies and allocations). Users can always call |
||
| else: | ||
| data = self._normalizer.denormalize(frame_data, norm) | ||
| if norm.HasField("custom"): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tz_datasymbol use an unnamed index before that behaviour has been introduced, I would just give it a name to avoid confusion when reading the notebook from start to finishcolumnslistto_df()that returns Polars or PyArrow, to show Pandas isn't necessary in that workflow?print(f"Number of record batches: {arrow_table.num_rows}")seems wrong