Skip to content

Commit

Permalink
Handle multiindex
Browse files Browse the repository at this point in the history
  • Loading branch information
Vasil Pashov committed Apr 1, 2024
1 parent f86640d commit 35ca8bc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
7 changes: 5 additions & 2 deletions python/arcticdb/version_store/_normalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,6 @@ def _from_tz_timestamp(ts, tz):
def _normalize_single_index(index, index_names, index_norm, dynamic_strings=None, string_max_len=None):
# index: pd.Index or np.ndarray -> np.ndarray
index_tz = None

if isinstance(index_norm, NormalizationMetadata.PandasIndex) and not index_norm.is_physically_stored:
if index.name:
if not isinstance(index.name, int) and not isinstance(index.name, str):
Expand Down Expand Up @@ -525,7 +524,11 @@ def denormalize(self, item, norm_meta):
class _PandasNormalizer(Normalizer):
def _index_to_records(self, df, pd_norm, dynamic_strings, string_max_len):
index = df.index
if isinstance(index, MultiIndex):
if len(index) == 0 and len(df.select_dtypes(include="category").columns) == 0:
index_norm = pd_norm.index
index_norm.is_physically_stored = False
index = Index([])
elif isinstance(index, MultiIndex):
# This is suboptimal and only a first implementation since it reduplicates the data
index_norm = pd_norm.multi_index
index_norm.field_count = len(index.levels) - 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def dtype(request):
yield request.param


@pytest.fixture(params=[pd.RangeIndex(0,0), pd.DatetimeIndex([])])
@pytest.fixture(params=[pd.RangeIndex(0,0), pd.DatetimeIndex([]), pd.MultiIndex.from_arrays([[],[]], names=["a", "b"])])
def empty_index(request):
yield request.param

Expand Down Expand Up @@ -569,6 +569,7 @@ def test_date(self, lmdb_version_store_static_and_dynamic, date_dtype):
)
)


class TestCanAppendToEmptyColumn:
"""
Tests that it's possible to append to a column which contains no rows. The type of the columns, including the index
Expand Down

0 comments on commit 35ca8bc

Please sign in to comment.