@@ -2410,6 +2410,7 @@ def generate_resource(
24102410 datecol : int | str | None = None ,
24112411 yearcol : int | str | None = None ,
24122412 date_function : Callable [[dict ], dict | None ] | None = None ,
2413+ no_empty : bool = True ,
24132414 ) -> tuple [bool , dict ]:
24142415 """Write rows to file and create resource, adding it to the dataset. The headers
24152416 argument is either a row number (rows start counting at 1), or the actual
@@ -2440,9 +2441,10 @@ def generate_resource(
24402441 columns: Columns to write. Defaults to all.
24412442 format: Format to write. Defaults to csv.
24422443 encoding: Encoding to use. Defaults to None (infer encoding).
2443- datecol: Optional[Union[int, str]] = None,
2444- yearcol: Optional[Union[int, str]] = None,
2445- date_function: Optional[Callable[[Dict], Optional[Dict]]] = None,
2444+ datecol: Date column for setting time period. Defaults to None (don't set).
2445+ yearcol: Year column for setting dataset year range. Defaults to None (don't set).
2446+ date_function: Date function to call for each row. Defaults to None.
2447+ no_empty: Don't generate resource if there are no data rows. Defaults to True.
24462448
24472449 Returns:
24482450 (True if resource added, dictionary of results)
@@ -2505,7 +2507,7 @@ def process_row(row: Sequence | Mapping) -> Sequence | Mapping | None:
25052507 encoding = encoding ,
25062508 row_function = process_row ,
25072509 )
2508- if not rows :
2510+ if not rows and no_empty :
25092511 logger .error (f"No data rows in { filename } !" )
25102512 return False , retdict
25112513 if yearcol is not None or date_function is not None :
@@ -2731,6 +2733,7 @@ def download_generate_resource(
27312733 datecol : int | str | None = None ,
27322734 yearcol : int | str | None = None ,
27332735 date_function : Callable [[dict ], dict | None ] | None = None ,
2736+ no_empty : bool = True ,
27342737 ** kwargs : Any ,
27352738 ) -> tuple [bool , dict ]:
27362739 """Download url, write rows to csv and create resource, adding to it
@@ -2769,9 +2772,10 @@ def download_generate_resource(
27692772 columns: Columns to write. Defaults to all.
27702773 format: Format to write. Defaults to csv.
27712774 encoding: Encoding to use. Defaults to None (infer encoding).
2772- datecol: Optional[Union[int, str]] = None,
2773- yearcol: Optional[Union[int, str]] = None,
2774- date_function: Optional[Callable[[Dict], Optional[Dict]]] = None,
2775+ datecol: Date column for setting time period. Defaults to None (don't set).
2776+ yearcol: Year column for setting dataset year range. Defaults to None (don't set).
2777+ date_function: Date function to call for each row. Defaults to None.
2778+ no_empty: Don't generate resource if there are no data rows. Defaults to True.
27752779 **kwargs: Any additional args to pass to downloader.get_tabular_rows
27762780
27772781 Returns:
@@ -2797,6 +2801,7 @@ def download_generate_resource(
27972801 datecol = datecol ,
27982802 yearcol = yearcol ,
27992803 date_function = date_function ,
2804+ no_empty = no_empty ,
28002805 )
28012806
28022807 def download_and_generate_resource (
0 commit comments