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

Made sorting on NdMapping optional #1217

Merged
merged 6 commits into from
Mar 24, 2017
Merged

Made sorting on NdMapping optional #1217

merged 6 commits into from
Mar 24, 2017

Conversation

philippjfr
Copy link
Member

@philippjfr philippjfr commented Mar 17, 2017

Let's users provide an explicitly sorted NdMapping. Still need to add a warning when a regular dict and sort=False are supplied since sort order is nondeterministic in that case.

Edit: Widgets are currently assuming sorted keys and NdElement seems to have been sorting in some cases.

Addresses: #1216

Fixes: #1042

@philippjfr philippjfr added type: feature A major new feature status: WIP labels Mar 17, 2017
@philippjfr philippjfr force-pushed the ndmapping_sort branch 2 times, most recently from 5d53e0d to 5159f37 Compare March 24, 2017 13:20
@philippjfr
Copy link
Member Author

Ready to review/merge when tests pass.

@@ -49,11 +49,11 @@ def __init__(self, enabled):
self.enabled = enabled

def __enter__(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

The docstring of this context_manager should be updated. As now sort=False is valid, it should just say it disables sorting regardless of whether the NdMapping has sort=True or sort=False.

I also think the line 'Should only be used if values are guaranteed to be sorted before or after the operation is performed.' should just say something else - maybe just that the initial ordering (whatever it is) should be preserved?

Copy link
Member Author

Choose a reason for hiding this comment

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

Docstring updated.

if name in own_params}, **params)
if isinstance(initial_items, MultiDimensionalMapping):
params = dict(util.get_param_values(initial_items),
**dict({'sort': self.sort}, **params))
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice to see the simplified constructor!

Copy link
Member Author

Choose a reason for hiding this comment

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

That's where the bug reported in #1042 was, this was written very early on before we had utilities for this kind of thing.

if not self._instantiated and self.get_dimension(dim).values == 'initial':
if val not in vals:
self._cached_index_values[dim.name].append(val)
elif vals and val is not None and val not in vals:
Copy link
Contributor

Choose a reason for hiding this comment

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

Was this chunk of logic made redundant by some other change or was it always redundant?

Copy link
Member Author

Choose a reason for hiding this comment

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

This was my early hacky approach to define a fixed order, I think it has been broken for a long time.

with item_check(False):
return util.ndmapping_groupby(self, dimensions, container_type,
group_type, sort=sort, **kwargs)
group_type, sort=True, **kwargs)
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably worth mentioning either in a comment - or maybe even the docstring - that sorting will always be applied.

Copy link
Member Author

Choose a reason for hiding this comment

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

Will do.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added to the docstring above.

@jlstevens
Copy link
Contributor

jlstevens commented Mar 24, 2017

Looks good. Most of my comments relate to documentation issues...

I agree a ValueError is better than a warning when sort=False and an unsortable dictionary is supplied. It is probably best to completely disallow the nondeterministic case rather than simply warning.

Edit: The tests do seem to be failing though...

@jlstevens
Copy link
Contributor

Tests are now fixed (pr build is passing at least) and you've made the docstring changes I suggested. Merging!

@jlstevens jlstevens merged commit 8cc5160 into master Mar 24, 2017
@philippjfr philippjfr deleted the ndmapping_sort branch April 11, 2017 12:29
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: feature A major new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants