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

Fixes issue (127) where append_date_dirs wasn't working properly. #130

Merged
merged 1 commit into from
Mar 31, 2022
Merged
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
11 changes: 7 additions & 4 deletions weather_dl/download_pipeline/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,9 @@ def require(condition: bool, message: str) -> None:
num_partition_keys = len(partition_keys)
if use_date_as_directory(config):
num_partition_keys -= 1
if str(params.get('target_path')).endswith('/'):
params['target_path'] = params.get('target_path')[:-1]
target_path = t.cast(str, params.get('target_path', ''))
if target_path != '':
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last nit: It this if statement necessary? I think rstrip on an empty string will produce an empty string.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, but I added it because you don't want to add a key to the dict if it doesn't already have it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though, generally, I'm not actually sure why this is located here, because it seems like it'd be more natural to handle it in prepare_target_name().

On a similar note, I think subtracting 1 from num_partition_keys here, but actually removing the "date" partition key in prepare_target_name(), might be a little risky. Could they be done in the same place?

Copy link
Collaborator

@alxmrs alxmrs Mar 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, but I added it because you don't want to add a key to the dict if it doesn't already have it.

Ah, that makes sense.

it seems like it'd be more natural to handle it in prepare_target_name().

I agree – this would be a better fit: It'd be best if the parser had less logic, in general.

Could they be done in the same place?

Yes, that totally sounds right to me.

Last: I think we are no longer using the num_partition_keys counter anymore. It would be prudent to pull that out.

params['target_path'] = target_path.rstrip('/')

require(num_template_replacements == num_partition_keys,
"""
Expand All @@ -352,10 +353,12 @@ def prepare_target_name(config: Config) -> str:

target_path = t.cast(str, parameters.get('target_path', ''))
target_filename = t.cast(str, parameters.get('target_filename', ''))
partition_keys = t.cast(t.List[str], parameters.get('partition_keys', list()))
partition_keys = t.cast(t.List[str],
cp.copy(parameters.get('partition_keys', list())))

if use_date_as_directory(config):
date_vals = config['selection']['date'][0].split('-')
date = t.cast(str, config['selection']['date'][0])
date_vals = date.split('-')
target_path = os.path.join(target_path, *date_vals)
partition_keys.remove('date')

Expand Down