Skip to content

Commit

Permalink
fix: correct zero row count in DataFrame from table view (#1062)
Browse files Browse the repository at this point in the history
* fix: correct zero row count display in DataFrame from table view

* update logic and test
  • Loading branch information
Genesis929 authored Oct 8, 2024
1 parent 650d80d commit b536070
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
4 changes: 3 additions & 1 deletion bigframes/core/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ class GbqTable:
table_id: str = field()
physical_schema: Tuple[bq.SchemaField, ...] = field()
n_rows: int = field()
is_physical_table: bool = field()
cluster_cols: typing.Optional[Tuple[str, ...]]

@staticmethod
Expand All @@ -523,6 +524,7 @@ def from_table(table: bq.Table, columns: Sequence[str] = ()) -> GbqTable:
table_id=table.table_id,
physical_schema=schema,
n_rows=table.num_rows,
is_physical_table=(table.table_type == "TABLE"),
cluster_cols=None
if table.clustering_fields is None
else tuple(table.clustering_fields),
Expand Down Expand Up @@ -603,7 +605,7 @@ def variables_introduced(self) -> int:

@property
def row_count(self) -> typing.Optional[int]:
if self.source.sql_predicate is None:
if self.source.sql_predicate is None and self.source.table.is_physical_table:
return self.source.table.n_rows
return None

Expand Down
20 changes: 20 additions & 0 deletions tests/system/small/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -1521,6 +1521,26 @@ def test_shape(scalars_dfs):
assert bf_result == pd_result


@pytest.mark.parametrize(
"reference_table, test_table",
[
(
"bigframes-dev.bigframes_tests_sys.base_table",
"bigframes-dev.bigframes_tests_sys.base_table_view",
),
(
"bigframes-dev.bigframes_tests_sys.csv_native_table",
"bigframes-dev.bigframes_tests_sys.csv_external_table",
),
],
)
def test_view_and_external_table_shape(session, reference_table, test_table):
reference_df = session.read_gbq(reference_table)
test_df = session.read_gbq(test_table)

assert test_df.shape == reference_df.shape


def test_len(scalars_dfs):
scalars_df, scalars_pandas_df = scalars_dfs
bf_result = len(scalars_df)
Expand Down

0 comments on commit b536070

Please sign in to comment.