GeezerVison is showing github.com — fix: empty record dtypes (#2147) · kiraksi/python-bigquery@77d7173
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: google/cloud/bigquery/table.py +18-24Lines changed: 18 additions & 24 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2648,31 +2648,25 @@ def to_dataframe( | 2648 | 2648 | if pyarrow.types.is_timestamp(col.type) | 2649 | 2649 | ) | 2650 | 2650 |
| 2651 | | - if len(record_batch) > 0: | 2652 | | - df = record_batch.to_pandas( | | 2651 | + df = record_batch.to_pandas( | | 2652 | + date_as_object=date_as_object, | | 2653 | + timestamp_as_object=timestamp_as_object, | | 2654 | + integer_object_nulls=True, | | 2655 | + types_mapper=_pandas_helpers.default_types_mapper( | 2653 | 2656 | date_as_object=date_as_object, | 2654 | | - timestamp_as_object=timestamp_as_object, | 2655 | | - integer_object_nulls=True, | 2656 | | - types_mapper=_pandas_helpers.default_types_mapper( | 2657 | | - date_as_object=date_as_object, | 2658 | | - bool_dtype=bool_dtype, | 2659 | | - int_dtype=int_dtype, | 2660 | | - float_dtype=float_dtype, | 2661 | | - string_dtype=string_dtype, | 2662 | | - date_dtype=date_dtype, | 2663 | | - datetime_dtype=datetime_dtype, | 2664 | | - time_dtype=time_dtype, | 2665 | | - timestamp_dtype=timestamp_dtype, | 2666 | | - range_date_dtype=range_date_dtype, | 2667 | | - range_datetime_dtype=range_datetime_dtype, | 2668 | | - range_timestamp_dtype=range_timestamp_dtype, | 2669 | | - ), | 2670 | | - ) | 2671 | | - else: | 2672 | | - # Avoid "ValueError: need at least one array to concatenate" on | 2673 | | - # older versions of pandas when converting empty RecordBatch to | 2674 | | - # DataFrame. See: https://github.com/pandas-dev/pandas/issues/41241 | 2675 | | - df = pandas.DataFrame([], columns=record_batch.schema.names) | | 2657 | + bool_dtype=bool_dtype, | | 2658 | + int_dtype=int_dtype, | | 2659 | + float_dtype=float_dtype, | | 2660 | + string_dtype=string_dtype, | | 2661 | + date_dtype=date_dtype, | | 2662 | + datetime_dtype=datetime_dtype, | | 2663 | + time_dtype=time_dtype, | | 2664 | + timestamp_dtype=timestamp_dtype, | | 2665 | + range_date_dtype=range_date_dtype, | | 2666 | + range_datetime_dtype=range_datetime_dtype, | | 2667 | + range_timestamp_dtype=range_timestamp_dtype, | | 2668 | + ), | | 2669 | + ) | 2676 | 2670 |
| 2677 | 2671 | for column in dtypes: | 2678 | 2672 | df[column] = pandas.Series(df[column], dtype=dtypes[column], copy=False) | |
Collapse file Copy file name to clipboardExpand all lines: pyproject.toml +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -72,7 +72,7 @@ bqstorage = [ | 72 | 72 | "pyarrow >= 4.0.0", | 73 | 73 | ] | 74 | 74 | pandas = [ | 75 | | - "pandas >= 1.1.4", | | 75 | + "pandas >= 1.3.0", | 76 | 76 | "pandas-gbq >= 0.26.1", | 77 | 77 | "grpcio >= 1.47.0, < 2.0.0", | 78 | 78 | "grpcio >= 1.49.1, < 2.0.0; python_version >= '3.11'", | |
Collapse file Copy file name to clipboardExpand all lines: testing/constraints-3.9.txt +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -21,7 +21,7 @@ opentelemetry-api==1.1.0 | 21 | 21 | opentelemetry-instrumentation==0.20b0 | 22 | 22 | opentelemetry-sdk==1.1.0 | 23 | 23 | packaging==24.2.0 | 24 | | -pandas==1.1.4 | | 24 | +pandas==1.3.0 | 25 | 25 | pandas-gbq==0.26.1 | 26 | 26 | proto-plus==1.22.3 | 27 | 27 | protobuf==3.20.2 | |
Collapse file Copy file name to clipboardExpand all lines: tests/system/test_pandas.py +1-6Lines changed: 1 addition & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1222,12 +1222,7 @@ def test_list_rows_nullable_scalars_extreme_dtypes_w_custom_dtype( | 1222 | 1222 |
| 1223 | 1223 | # These pandas dtypes are handled by the custom dtypes. | 1224 | 1224 | assert df.dtypes["bool_col"].name == "boolean" | 1225 | | - # Result is dependent upon which version of pandas is being used. | 1226 | | - # Float64 was not introduced until pandas version 1.4. | 1227 | | - if PANDAS_INSTALLED_VERSION >= "1.4": | 1228 | | - assert df.dtypes["float64_col"].name == "Float64" | 1229 | | - else: | 1230 | | - assert df.dtypes["float64_col"].name == "string" | | 1225 | + assert df.dtypes["float64_col"].name == "Float64" | 1231 | 1226 | assert df.dtypes["int64_col"].name == "Int64" | 1232 | 1227 | assert df.dtypes["string_col"].name == "string" | 1233 | 1228 |
| |
Collapse file Copy file name to clipboardExpand all lines: tests/unit/test_table.py +2-8Lines changed: 2 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -4143,14 +4143,8 @@ def test_to_dataframe_w_dtypes_mapper(self): | 4143 | 4143 | ) | 4144 | 4144 | self.assertEqual(df.name.dtype.name, "string") | 4145 | 4145 |
| 4146 | | - # While pyproject.toml lists pandas 1.1 as the lowest supported version of | 4147 | | - # pandas, the pip resolver is not able to resolve pandas 1.1 and numpy | 4148 | | - if hasattr(pandas, "Float64Dtype"): | 4149 | | - self.assertEqual(list(df.miles), [1.77, 6.66, 2.0]) | 4150 | | - self.assertEqual(df.miles.dtype.name, "Float64") | 4151 | | - else: | 4152 | | - self.assertEqual(list(df.miles), ["1.77", "6.66", "2.0"]) | 4153 | | - self.assertEqual(df.miles.dtype.name, "string") | | 4146 | + self.assertEqual(list(df.miles), [1.77, 6.66, 2.0]) | | 4147 | + self.assertEqual(df.miles.dtype.name, "Float64") | 4154 | 4148 |
| 4155 | 4149 | if hasattr(pandas, "ArrowDtype"): | 4156 | 4150 | self.assertEqual( | |
|