Create and validate BuilderConfig object as well as a unique config id for this config. Raises ValueError if there are multiple builder configs and config_name and DEFAULT_CONFIG_NAME are None. config_kwargs override the defaults kwargs in config
(
self, config_name=None, custom_features=None, config_id=None, **config_kwargs
)
| 501 | return legacy_relative_data_dir |
| 502 | |
| 503 | def _create_builder_config( |
| 504 | self, config_name=None, custom_features=None, config_id=None, **config_kwargs |
| 505 | ) -> tuple[BuilderConfig, str]: |
| 506 | """Create and validate BuilderConfig object as well as a unique config id for this config. |
| 507 | Raises ValueError if there are multiple builder configs and config_name and DEFAULT_CONFIG_NAME are None. |
| 508 | config_kwargs override the defaults kwargs in config |
| 509 | """ |
| 510 | builder_config = None |
| 511 | |
| 512 | # try default config |
| 513 | if config_name is None and self.BUILDER_CONFIGS: |
| 514 | if self.DEFAULT_CONFIG_NAME is not None: |
| 515 | builder_config = self.builder_configs.get(self.DEFAULT_CONFIG_NAME) |
| 516 | logger.info(f"No config specified, defaulting to: {self.dataset_name}/{builder_config.name}") |
| 517 | else: |
| 518 | if len(self.BUILDER_CONFIGS) > 1: |
| 519 | if not config_kwargs: |
| 520 | example_of_usage = ( |
| 521 | f"load_dataset('{self.repo_id or self.dataset_name}', '{self.BUILDER_CONFIGS[0].name}')" |
| 522 | ) |
| 523 | raise ValueError( |
| 524 | "Config name is missing." |
| 525 | f"\nPlease pick one among the available configs: {list(self.builder_configs.keys())}" |
| 526 | + f"\nExample of usage:\n\t`{example_of_usage}`" |
| 527 | ) |
| 528 | else: |
| 529 | builder_config = self.BUILDER_CONFIGS[0] |
| 530 | logger.info( |
| 531 | f"No config specified, defaulting to the single config: {self.dataset_name}/{builder_config.name}" |
| 532 | ) |
| 533 | |
| 534 | # try to get config by name |
| 535 | if isinstance(config_name, str): |
| 536 | builder_config = self.builder_configs.get(config_name) |
| 537 | if builder_config is None and self.BUILDER_CONFIGS: |
| 538 | raise ValueError( |
| 539 | f"BuilderConfig '{config_name}' not found. Available: {list(self.builder_configs.keys())}" |
| 540 | ) |
| 541 | |
| 542 | # if not using an existing config, then create a new config on the fly |
| 543 | if not builder_config: |
| 544 | if config_name is not None: |
| 545 | config_kwargs["name"] = config_name |
| 546 | elif self.DEFAULT_CONFIG_NAME and not config_kwargs: |
| 547 | # Use DEFAULT_CONFIG_NAME only if no config_kwargs are passed |
| 548 | config_kwargs["name"] = self.DEFAULT_CONFIG_NAME |
| 549 | if "version" not in config_kwargs and hasattr(self, "VERSION") and self.VERSION: |
| 550 | config_kwargs["version"] = self.VERSION |
| 551 | builder_config = self.BUILDER_CONFIG_CLASS(**config_kwargs) |
| 552 | |
| 553 | # otherwise use the config_kwargs to overwrite the attributes |
| 554 | else: |
| 555 | builder_config = copy.deepcopy(builder_config) if config_kwargs else builder_config |
| 556 | for key, value in config_kwargs.items(): |
| 557 | if value is not None: |
| 558 | if not hasattr(builder_config, key): |
| 559 | raise ValueError(f"BuilderConfig {builder_config} doesn't have a '{key}' key.") |
| 560 | setattr(builder_config, key, value) |
no test coverage detected