Commit 38cc43f
committed
feat: Implement read_arrow with deferred loading via pandas conversion
This commit implements `bigframes.pandas.read_arrow()` for creating
BigQuery DataFrames DataFrames from `pyarrow.Table` objects. This version
uses a deferred loading mechanism by first converting the Arrow table
to a pandas DataFrame (using `ArrowDtype` for type mapping) and then
leveraging `Block.from_local()`.
This approach simplifies `read_arrow` by removing the `write_engine`
parameter and ensures that `Block.from_local()` retains its original
behavior of only accepting pandas objects.
Key changes:
1. **`bigframes.core.blocks.Block.from_local` Reverted**:
* Restored `Block.from_local` to only accept `pandas.DataFrame`
or `pandas.Series` as input. Direct `pyarrow.Table` support
was removed from this method.
2. **`Session.read_arrow` and `Session._read_arrow` Updated**:
* The `write_engine` parameter was removed from these methods in
`bigframes/session/__init__.py`.
* `Session._read_arrow` now converts the input `pyarrow.Table`
to a `pandas.DataFrame` using
`arrow_table.to_pandas(types_mapper=pd.ArrowDtype)`.
* This pandas DataFrame is then passed to
`blocks.Block.from_local(pandas_df, self)` to create a
deferred block.
3. **Public API `bpd.read_arrow` Updated**:
* The `write_engine` parameter was removed from
`bigframes.pandas.read_arrow` in `bigframes/pandas/io/api.py`.
* Docstrings updated to reflect deferred loading.
4. **Test Updates**:
* Tests in `tests/system/small/test_read_arrow.py` were verified
to be consistent with this deferred loading approach.
Comparison logic uses
`arrow_table.to_pandas(types_mapper=pd.ArrowDtype)` for the
expected DataFrame and `check_dtype=True` in assertions.1 parent 813ef35 commit 38cc43f
2 files changed
+42
-66
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
| 39 | + | |
| 40 | + | |
40 | 41 | | |
41 | 42 | | |
42 | 43 | | |
| |||
159 | 160 | | |
160 | 161 | | |
161 | 162 | | |
162 | | - | |
| 163 | + | |
163 | 164 | | |
164 | 165 | | |
165 | 166 | | |
| |||
170 | 171 | | |
171 | 172 | | |
172 | 173 | | |
| 174 | + | |
173 | 175 | | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
| 176 | + | |
| 177 | + | |
191 | 178 | | |
192 | 179 | | |
193 | 180 | | |
| |||
236 | 223 | | |
237 | 224 | | |
238 | 225 | | |
239 | | - | |
| 226 | + | |
240 | 227 | | |
241 | 228 | | |
242 | 229 | | |
| |||
248 | 235 | | |
249 | 236 | | |
250 | 237 | | |
251 | | - | |
252 | | - | |
253 | | - | |
| 238 | + | |
254 | 239 | | |
255 | 240 | | |
256 | 241 | | |
| |||
3412 | 3397 | | |
3413 | 3398 | | |
3414 | 3399 | | |
| 3400 | + | |
| 3401 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
917 | 917 | | |
918 | 918 | | |
919 | 919 | | |
| 920 | + | |
920 | 921 | | |
921 | 922 | | |
922 | 923 | | |
923 | 924 | | |
924 | | - | |
925 | | - | |
926 | 925 | | |
927 | 926 | | |
928 | 927 | | |
929 | | - | |
| 928 | + | |
930 | 929 | | |
931 | 930 | | |
932 | 931 | | |
933 | 932 | | |
934 | | - | |
935 | | - | |
936 | | - | |
937 | | - | |
938 | | - | |
939 | | - | |
940 | | - | |
941 | | - | |
942 | | - | |
943 | | - | |
944 | | - | |
945 | | - | |
| 933 | + | |
946 | 934 | | |
947 | | - | |
948 | | - | |
949 | | - | |
950 | | - | |
951 | | - | |
952 | | - | |
953 | | - | |
954 | | - | |
955 | | - | |
956 | | - | |
957 | | - | |
958 | | - | |
959 | | - | |
960 | | - | |
961 | | - | |
962 | | - | |
963 | | - | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
964 | 938 | | |
965 | 939 | | |
966 | 940 | | |
967 | | - | |
| 941 | + | |
968 | 942 | | |
969 | 943 | | |
970 | 944 | | |
971 | | - | |
972 | | - | |
973 | | - | |
974 | | - | |
975 | | - | |
976 | | - | |
| 945 | + | |
977 | 946 | | |
978 | | - | |
979 | | - | |
980 | | - | |
| 947 | + | |
981 | 948 | | |
982 | 949 | | |
983 | 950 | | |
| 951 | + | |
984 | 952 | | |
985 | 953 | | |
986 | 954 | | |
| |||
1054 | 1022 | | |
1055 | 1023 | | |
1056 | 1024 | | |
1057 | | - | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
1058 | 1047 | | |
1059 | 1048 | | |
1060 | 1049 | | |
| |||
0 commit comments