Skip to content

Commit

Permalink
add fallback to private attritbute for known datasets
Browse files Browse the repository at this point in the history
Signed-off-by: Sajid Alam <[email protected]>
  • Loading branch information
SajidAlamQB committed Nov 6, 2024
1 parent 7b31509 commit fef1a23
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 17 deletions.
3 changes: 3 additions & 0 deletions package/kedro_viz/integrations/kedro/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ def get_file_size(self, dataset: Any) -> Union[int, None]:
try:
if hasattr(dataset, "filepath") and dataset.filepath:
filepath = dataset.filepath
# Fallback to private '_filepath' for known datasets
elif hasattr(dataset, "_filepath") and dataset._filepath:
filepath = dataset._filepath
else:
return None

Expand Down
17 changes: 0 additions & 17 deletions package/tests/test_integrations/test_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,20 +137,3 @@ def test_get_file_size(dataset, example_dataset_stats_hook_obj, example_csv_data
assert example_dataset_stats_hook_obj.get_file_size(
example_csv_dataset
) == example_csv_dataset._fs.size(file_path)


def test_get_file_size_no_protocol(example_dataset_stats_hook_obj, mocker):
class MockDataset:
def __init__(self):
self._filepath = "/path/to/dataset.csv"

mock_dataset = MockDataset()

mocker.patch(
"kedro_viz.integrations.kedro.hooks.get_filepath_str",
return_value=mock_dataset._filepath,
)

# Call get_file_size and expect it to return None
file_size = example_dataset_stats_hook_obj.get_file_size(mock_dataset)
assert file_size is None

0 comments on commit fef1a23

Please sign in to comment.