-
Notifications
You must be signed in to change notification settings - Fork 4
feat: Add parquet file size in final statistics #75
Changes from 2 commits
5718ecb
496fe85
4fa016a
cf01a5a
b558e8c
6d91a92
82e5720
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -511,6 +511,26 @@ def format_date(date: datetime | str) -> str: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| raise TypeError(msg) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def convert_file_size_in_bytes_to_human_readable_format(size_in_bytes: float) -> str: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """Convert file size in bytes to a human-readable format. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Parameters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ---------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| size_in_bytes : float | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| File size in bytes. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Returns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| str | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| File size in a human-readable format (e.g., '10.5 MB'). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for unit in ["B", "KB", "MB", "GB", "TB"]: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if size_in_bytes < 1024.0: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return f"{size_in_bytes:.2f} {unit}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| size_in_bytes /= 1024.0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return "File too big!" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def print_statistics( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| scraper: ScraperContext, logger: "loguru.Logger" = loguru.logger | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) -> None: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -527,9 +547,15 @@ def print_statistics( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| logger.success( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| f"Number of datasets scraped: {scraper.number_of_datasets_scraped:,}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| logger.info(f"Saved in: {scraper.datasets_parquet_file_path}") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| file_size = convert_file_size_in_bytes_to_human_readable_format( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| scraper.datasets_parquet_file_path.stat().st_size | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| logger.info(f"Saved in: {scraper.datasets_parquet_file_path} ({file_size})") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| file_size = convert_file_size_in_bytes_to_human_readable_format( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| scraper.files_parquet_file_path.stat().st_size | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| file_size = convert_file_size_in_bytes_to_human_readable_format( | |
| scraper.datasets_parquet_file_path.stat().st_size | |
| ) | |
| logger.info(f"Saved in: {scraper.datasets_parquet_file_path} ({file_size})") | |
| file_size = convert_file_size_in_bytes_to_human_readable_format( | |
| scraper.files_parquet_file_path.stat().st_size | |
| ) | |
| if scraper.datasets_parquet_file_path.is_file(): | |
| file_size = convert_file_size_in_bytes_to_human_readable_format( | |
| scraper.datasets_parquet_file_path.stat().st_size | |
| ) | |
| logger.info( | |
| f"Saved in: {scraper.datasets_parquet_file_path} ({file_size})" | |
| ) | |
| else: | |
| logger.warning( | |
| f"Datasets parquet file not found at: {scraper.datasets_parquet_file_path}" | |
| ) | |
| logger.info( | |
| f"Saved in: {scraper.datasets_parquet_file_path} (size unknown)" | |
| ) | |
| if scraper.files_parquet_file_path.is_file(): | |
| file_size = convert_file_size_in_bytes_to_human_readable_format( | |
| scraper.files_parquet_file_path.stat().st_size | |
| ) | |
| else: | |
| logger.warning( | |
| f"Files parquet file not found at: {scraper.files_parquet_file_path}" | |
| ) | |
| file_size = "size unknown" |
Outdated
Copilot
AI
Jan 27, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code calls .stat().st_size on the parquet file paths without error handling. If the export_list_of_models_to_parquet function fails (which can happen based on its exception handling in src/mdverse_scrapers/models/utils.py:172-175), the parquet files may not exist, causing a FileNotFoundError when .stat() is called. Consider adding a try-except block or checking if the file exists before attempting to get its size.
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,82 @@ | ||||||||||||||
| """Tests for the toolbox module.""" | ||||||||||||||
|
|
||||||||||||||
| from mdverse_scrapers.core.toolbox import ( | ||||||||||||||
| convert_file_size_in_bytes_to_human_readable_format, | ||||||||||||||
| ) | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| class TestConvertFileSizeInBytesToHumanReadableFormat: | ||||||||||||||
| """Tests for convert_file_size_in_bytes_to_human_readable_format function.""" | ||||||||||||||
|
||||||||||||||
| class TestConvertFileSizeInBytesToHumanReadableFormat: | |
| """Tests for convert_file_size_in_bytes_to_human_readable_format function.""" | |
| class TestConvertFileSizeToHumanReadable: | |
| """Tests for convert_file_size_to_human_readable function.""" |
Outdated
Copilot
AI
Jan 27, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docstring references convert_file_size_in_bytes_to_human_readable_format function, but the actual function name is convert_file_size_to_human_readable. The docstring should accurately reflect the function being tested.
| """Tests for convert_file_size_in_bytes_to_human_readable_format function.""" | |
| """Tests for convert_file_size_to_human_readable function.""" |
Outdated
Copilot
AI
Jan 27, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test suite is missing test cases for invalid inputs, particularly negative values. Since the function accepts a float parameter, it should handle negative values appropriately (e.g., by raising a ValueError or returning an error message). Add a test case to verify the behavior when a negative value is passed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function uses binary units (1024-based) for file size conversion (1 KB = 1024 B), while the FileMetadata.file_size_with_human_readable_unit property uses decimal units (1000-based) via ByteSize.human_readable(decimal=True). This inconsistency could confuse users seeing different unit conventions in the same application. Consider using the same unit convention throughout, or clearly documenting why different conventions are used. The industry standard for file sizes in operating systems is typically binary (1024-based), while storage devices typically use decimal (1000-based).