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

ConfigSet from arbitrary iterable & subscriptable ConfigSet #229

Open
gelzinyte opened this issue Mar 7, 2023 · 1 comment
Open

ConfigSet from arbitrary iterable & subscriptable ConfigSet #229

gelzinyte opened this issue Mar 7, 2023 · 1 comment
Labels
enhancement (not new) improving existing functionality

Comments

@gelzinyte
Copy link
Contributor

Moving discussion from PR #222 here. (link to the thread)

First, have an __gettitem__ method

from itertools import islice
.
.
.
  def __getitem__(self, arg):
      if isinstance(arg, slice):
          return islice(self, arg.start, arg.stop, arg.step)
      elif isinstance(arg, int):
          return list(islice(self, arg, arg + 1, 1))[0]
      else:
          raise TypeError

Second, make it so ConfigSet can be constructed from an arbitrary iterable.

This came from wanting a (slightly) simpler interface, where ConfigSet behaves more like a list:

subsample_configset = ConfigSet(in_configset[::2])

Currently that can be done by converting to list and back

subsample_configset = ConfigSet(list(in_configset)[::2])

Not sure if this simpler interface is worth the changes, but being able to create ConfigSets from arbitrary iterable/generator might be useful?

@gelzinyte gelzinyte added the enhancement (not new) improving existing functionality label Mar 7, 2023
@bernstei
Copy link
Contributor

bernstei commented Mar 7, 2023

For this to be a sensible addition we really have to think carefully about what this means. When you create the new ConfigSet, should it be in memory? Or should it just keep a reference to the input iterable and step through it ass needed? What about an iterable that contains other iterables, perhaps lists, perhaps arbitrary?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement (not new) improving existing functionality
Projects
None yet
Development

No branches or pull requests

2 participants