Skip to content

Conversation

@Ian0sborne
Copy link
Contributor

@Ian0sborne Ian0sborne commented Oct 2, 2025

This PR fixes #941 whereby some arguments in write_city_configuration were over the 300 character threshold. This issue occurred when passing dictionary arguments without unpacking them. This PR makes the write_city_configuration function sensitive to dictionary arguments and unpacks them, assigning sensible names. I have also added a case for this in the test function.

@gonzaponte
Copy link
Collaborator

This looks pretty good.

I would it to be a bit more general, allowing an arbitrary level of nesting. I would go for a recursive approach.

@Ian0sborne
Copy link
Contributor Author

I have tried to come up with an iterative approach by adding a new function. Not sure if this is ugly though?

def flatten_dict(arg : dict,
                parent_key : str= "",
                dev : str= "."):
    flat_dict = {}
    for k, v in arg.items():
        new_key = f"{parent_key}{dev}{k}" if parent_key else k
        if isinstance(v, dict):
            flat_dict.update(flatten_dict(v, new_key))
        else:
            flat_dict[new_key] = str(v)
    return flat_dict

This would output something like:
image

Let me know what you think and I will implement it

@Ian0sborne Ian0sborne force-pushed the improve-config-parameters branch 2 times, most recently from e7bc4b8 to 2573967 Compare October 6, 2025 15:21
Copy link
Collaborator

@gonzaponte gonzaponte left a comment

Choose a reason for hiding this comment

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

Apologies for the late reply. I've had a hectic couple of weeks.

The proposed solution is excellent, I think. Just a minor comment: you either remove the dev argument (what does it stand for?) or pass it as an argument when you call the function from within the loop. I don't think we want to make it this generic, but both approaches are fine by me.

@Ian0sborne
Copy link
Contributor Author

No need to apologise!

You're absolutely right Gonzalo: the "dev" was meant to stand for "divider" (but I made a typo). There's no need for it to be an argument so I'll implement that and the rest of the changes now.

@gonzaponte
Copy link
Collaborator

Sorry, I thought I have already commented here. This is almost ready, let's rewrite the commit history following these recommendations. After that, I'll approve it.

@Ian0sborne Ian0sborne force-pushed the improve-config-parameters branch 2 times, most recently from fcb857d to f02f34f Compare October 22, 2025 09:57
@Ian0sborne
Copy link
Contributor Author

Hi Gonzalo! Is the commit history okay now?

@gonzaponte
Copy link
Collaborator

The second commit says "Alter function & test...", but the changes are more like "Introduce function and alter test ...". I suggest you put the second version of the test (the one prior to "simplification") already in the first commit and then introduce the final version of the function in the second commit, leaving the third one as it is now. Let me know if you need help with this.

@Ian0sborne
Copy link
Contributor Author

I'll try this now, will let you know if I need help. Thanks!

@Ian0sborne Ian0sborne force-pushed the improve-config-parameters branch from f02f34f to 7384771 Compare October 22, 2025 11:37
@Ian0sborne
Copy link
Contributor Author

I think this should be better now.

I was not able to put the second version of the testing function in the first commit because I committed it at the same time as the "final version" of the unpacking function. For this reason, I thought they would be better in the second commit together.

Let me know what you think of these changes

@Ian0sborne Ian0sborne force-pushed the improve-config-parameters branch from a4b9990 to ecb27c6 Compare October 23, 2025 14:47
@gonzaponte
Copy link
Collaborator

The history has been rewritten with peras to learn some magit.

Copy link
Collaborator

@gonzaponte gonzaponte left a comment

Choose a reason for hiding this comment

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

Handles nested dictionaries elegantly in the config output. And it's tested. Nice job!

@Ian0sborne Ian0sborne changed the title Improve config parameters Improve config parameters to handle nested dictionary entries Oct 23, 2025
@Ian0sborne Ian0sborne changed the title Improve config parameters to handle nested dictionary entries Handle nested dictionaries in config parameter storage Oct 23, 2025
@gonzaponte
Copy link
Collaborator

@Luismiguelvillar please merge!

@Luismiguelvillar Luismiguelvillar merged commit 0657e37 into next-exp:master Oct 24, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Configs stored in h5 files too short, losing parameter information

3 participants