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

fix: correct zero row count in DataFrame from table view #1062

Merged
merged 2 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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