Skip to content

Commit

Permalink
Fix an issue in referencing multidimensional columns by names with di…
Browse files Browse the repository at this point in the history
…ct notation
  • Loading branch information
smathot committed Nov 21, 2024
1 parent 27eea9a commit 11360a0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 2 additions & 0 deletions datamatrix/_datamatrix/_datamatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,8 @@ def _slice(self, key):
# and row. Therefore, we turn tuples into lists.
if isinstance(key, tuple):
key = list(key)
if isinstance(key[0], str):
return self._getcolbyname(key[0])[key[1:]]
_rowid = self._rowid[key]
dm = DataMatrix(len(_rowid))
object.__setattr__(dm, u'_rowid', _rowid)
Expand Down
11 changes: 5 additions & 6 deletions datamatrix/_datamatrix/_multidimensionalcolumn.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@
from datamatrix import cfg
from datamatrix._datamatrix._numericcolumn import NumericColumn, FloatColumn
from datamatrix._datamatrix._datamatrix import DataMatrix
try:
from collections.abc import Sequence # Python 3.3 and later
except ImportError:
from collections import Sequence
from collections.abc import Sequence, Collection
from collections import OrderedDict
try:
import numpy as np
Expand Down Expand Up @@ -103,7 +100,9 @@ def __init__(self, datamatrix, shape, defaultnan=True, **kwargs):
normshape += (dim_size, )
self.index_names.append(list(range(dim_size)))
self.index_values.append(list(range(dim_size)))
else:
elif isinstance(dim_size, Collection):
if isinstance(dim_size, str):
raise ValueError('A dimension cannot be a string')
normshape += (len(dim_size), )
self.index_names.append(list(dim_size))
self.index_values.append(list(range(len(dim_size))))
Expand Down Expand Up @@ -417,7 +416,7 @@ def _getintkey(self, key):

def __getitem__(self, key):
touch_history.touch(self, try_to_load=True)
if isinstance(key, tuple) and len(key) <= len(self._seq.shape):
if isinstance(key, (tuple, list)) and len(key) <= len(self._seq.shape):
# Advanced indexing always returns a copy, rather than a view, so
# there's no need to explicitly copy the result.
indices = self._numindices(key, accept_ellipsis=True)
Expand Down

0 comments on commit 11360a0

Please sign in to comment.