From bb76ecfbfb82ce74ce67657b43c3573d306a0eda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20=C5=81opaciuk?= Date: Fri, 21 Jun 2024 15:14:01 +0200 Subject: [PATCH] Fixes in table when strings stored as objects --- xdeps/table.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/xdeps/table.py b/xdeps/table.py index 32ed24c..20c39f8 100644 --- a/xdeps/table.py +++ b/xdeps/table.py @@ -98,7 +98,7 @@ def __getitem__(self, key): raise IndexError( f"Cannot find `{key}` in table index `{self.table._index}`") elif hasattr(key, "dtype"): - if key.dtype.kind in "SU": + if key.dtype.kind in "SUO": if self.table._multiple_row_selections: mask[self.table._get_names_indices(key)] = True else: @@ -220,7 +220,7 @@ def __init__( index_cache=None, cast_strings=True ): - self._data = data + self._data = {kk: data[kk] for kk in data.keys()} self._col_names = list(data.keys() if col_names is None else col_names) for kk in self._col_names: @@ -229,7 +229,8 @@ def __init__( raise ValueError(f"Column `{kk}` is not a numpy array") else: if cast_strings and vv.dtype.kind in "SU": - data[kk] = np.array(vv, dtype=object) + vv = np.array(vv, dtype=object) + self._data[kk] = vv self._index = index self._count_sep = count_sep self._offset_sep = offset_sep @@ -550,7 +551,7 @@ def show( colwidth = len(cc) width += colwidth + 1 if width < maxwidth: - if coltype in "SU": + if coltype in "SUO": fmt.append("%%-%ds" % (colwidth)) else: fmt.append("%%%ds" % colwidth)