Skip to content

Commit

Permalink
fix: (v1) merging options should produce an option (#2582)
Browse files Browse the repository at this point in the history
* fix: don't overwrite `is_option`

* test: add test
  • Loading branch information
agoose77 committed Jul 19, 2023
1 parent 38237d6 commit f9f6ee7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
3 changes: 0 additions & 3 deletions src/libawkward/array/IndexedArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1870,7 +1870,6 @@ namespace awkward {
}

if (IndexedArray32* raw = dynamic_cast<IndexedArray32*>(array.get())) {
is_option = false;
contents.push_back(raw->content());
Index32 array_index = raw->index();
struct Error err = kernel::IndexedArray_fill<int32_t, int64_t>(
Expand All @@ -1885,7 +1884,6 @@ namespace awkward {
length_so_far += array.get()->length();
}
else if (IndexedArrayU32* raw = dynamic_cast<IndexedArrayU32*>(array.get())) {
is_option = false;
contents.push_back(raw->content());
IndexU32 array_index = raw->index();
struct Error err = kernel::IndexedArray_fill<uint32_t, int64_t>(
Expand All @@ -1900,7 +1898,6 @@ namespace awkward {
length_so_far += array.get()->length();
}
else if (IndexedArray64* raw = dynamic_cast<IndexedArray64*>(array.get())) {
is_option = false;
contents.push_back(raw->content());
Index64 array_index = raw->index();
struct Error err = kernel::IndexedArray_fill<int64_t, int64_t>(
Expand Down
17 changes: 17 additions & 0 deletions tests/test_2582-merge-option-non-option.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# BSD 3-Clause License; see https://github.com/scikit-hep/awkward-1.0/blob/main/LICENSE

import numpy as np # noqa: F401
import pytest # noqa: F401

import awkward as ak # noqa: F401


def test_merge_option():
x = ak.layout.IndexedArray64(
ak.layout.Index64([0, 1]), ak.layout.NumpyArray([1, 2, 3])
)
y = ak.layout.IndexedOptionArray64(
ak.layout.Index64([0, 1, -1]), ak.layout.NumpyArray([1, 2, 3])
)

assert isinstance(ak.concatenate((y, x)).layout, ak.layout.IndexedOptionArray64)

0 comments on commit f9f6ee7

Please sign in to comment.