Skip to content

Allow slicing of Variables objects #1069

Description

@arcondello
In [1]: import dimod

In [2]: bqm = dimod.BQM({'a': 1, 'b': 2}, {'ab': 1}, 1.5, 'SPIN')

In [3]: bqm.variables[:1]
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-3-10b8e511cd1e> in <module>
----> 1 bqm.variables[:1]

~/projects/ocean/dimod/dimod/cyvariables.pyx in dimod.cyvariables.cyVariables.__getitem__()
     48 
     49     # todo: support slices
---> 50     def __getitem__(self, Py_ssize_t idx):
     51         return self.at(idx)
     52 

TypeError: 'slice' object cannot be interpreted as an integer

it would be nice if instead we got a list.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions