Skip to content

[FEATURE REQUEST] Make it compatible with C++17 and newer #501

@kgizdov

Description

@kgizdov

Describe the issue

Not compatible with C++17 or newer.

Steps to reproduce

Build with C++17 or newer and get the following errors during testing:

=================================== FAILURES ===================================
_____________________________ TestBoolean.test_len _____________________________

self = <test_axis.TestBoolean object at 0x7ff812637b20>

    def test_len(self):
        a = bh.axis.Boolean()
>       assert len(a) == 2

tests/test_axis.py:862:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <[TypeError('(): incompatible function arguments. The following argument types are supported:\n    1. (arg0: boost_his... -> int\n\nInvoked with: integer(0, 2, metadata={}, options=none)') raised in repr()] Boolean object at 0x7ff812637a00>

    def __len__(self):
>       return self._ax.size
E       TypeError: (): incompatible function arguments. The following argument types are supported:
E           1. (arg0: boost_histogram._core.axis.integer_none) -> int
E
E       Invoked with: integer(0, 2, metadata={}, options=none)

build/lib.linux-x86_64-3.9/boost_histogram/_internal/axis.py:127: TypeError
____________________________ TestBoolean.test_repr _____________________________

self = <test_axis.TestBoolean object at 0x7ff8124e7d60>

    def test_repr(self):
        a = bh.axis.Boolean()
>       assert repr(a) == "Boolean()"

tests/test_axis.py:868:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
build/lib.linux-x86_64-3.9/boost_histogram/_internal/axis.py:151: in __repr__
    self=self, args=self._repr_args(), kwargs=self._repr_kwargs()
build/lib.linux-x86_64-3.9/boost_histogram/_internal/axis.py:681: in _repr_args
    if self.size == 2:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <[TypeError('(): incompatible function arguments. The following argument types are supported:\n    1. (arg0: boost_his... -> int\n\nInvoked with: integer(0, 2, metadata={}, options=none)') raised in repr()] Boolean object at 0x7ff8124e7c70>

    @property
    def size(self):
        """
        Return number of bins excluding under- and overflow.
        """
>       return self._ax.size
E       TypeError: (): incompatible function arguments. The following argument types are supported:
E           1. (arg0: boost_histogram._core.axis.integer_none) -> int
E
E       Invoked with: integer(0, 2, metadata={}, options=none)

build/lib.linux-x86_64-3.9/boost_histogram/_internal/axis.py:204: TypeError
___________________________ TestBoolean.test_getitem ___________________________

self = <test_axis.TestBoolean object at 0x7ff8124f8f40>

    def test_getitem(self):
        a = bh.axis.Boolean()
        ref = [False, True]
        for i, r in enumerate(ref):
            assert a.bin(i) == r
>           assert a[i] == r

tests/test_axis.py:884:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <[TypeError('(): incompatible function arguments. The following argument types are supported:\n    1. (arg0: boost_his... -> int\n\nInvoked with: integer(0, 2, metadata={}, options=none)') raised in repr()] Boolean object at 0x7ff8124f85b0>
i = 0

    def __getitem__(self, i):
        """
        Access a bin, using normal Python syntax for wraparound.
        """
        # UHI support
        if callable(i):
            i = i(self)
        else:
            if i < 0:
                i += self._ax.size
>           if i >= self._ax.size:
E           TypeError: (): incompatible function arguments. The following argument types are supported:
E               1. (arg0: boost_histogram._core.axis.integer_none) -> int
E
E           Invoked with: integer(0, 2, metadata={}, options=none)

build/lib.linux-x86_64-3.9/boost_histogram/_internal/axis.py:223: TypeError
____________________________ TestBoolean.test_iter _____________________________

self = <test_axis.TestBoolean object at 0x7ff8129e98b0>

    def test_iter(self):
        a = bh.axis.Boolean()
        ref = (False, True)
>       assert_array_equal(a, ref)
E       AssertionError:
E       Arrays are not equal
E
E       Mismatched elements: 1 / 1 (100%)
E        x: [repr failed for <ndarray>: (): incompatible function arguments. The following argument types are supported:
E           1. (arg0: boost_histogram._core.axis.integer_none) -> int
E
E       Invoked with: integer(0, 2, metadata={}, options=none)]
E        y: array([False,  True])

tests/test_axis.py:891: AssertionError
______________________________ test_hist_hist_div ______________________________

    def test_hist_hist_div():
        h1 = bh.Histogram(bh.axis.Boolean())
        h2 = bh.Histogram(bh.axis.Boolean())

>       h1[:] = (8, 6)

tests/test_histogram.py:530:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
build/lib.linux-x86_64-3.9/boost_histogram/_internal/hist.py:790: in __setitem__
    stop = len(self.axes[n]) if request.stop is None else request.stop
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <[TypeError('(): incompatible function arguments. The following argument types are supported:\n    1. (arg0: boost_his... -> int\n\nInvoked with: integer(0, 2, metadata={}, options=none)') raised in repr()] Boolean object at 0x7ff8125b1d30>

    def __len__(self):
>       return self._ax.size
E       TypeError: (): incompatible function arguments. The following argument types are supported:
E           1. (arg0: boost_histogram._core.axis.integer_none) -> int
E
E       Invoked with: integer(0, 2, metadata={}, options=none)

build/lib.linux-x86_64-3.9/boost_histogram/_internal/axis.py:127: TypeError
________________________________ test_pick_bool ________________________________

    def test_pick_bool():
        h = bh.Histogram(bh.axis.Boolean(), bh.axis.Boolean(metadata={"one": 1}))

        h.fill([True, True, False, False], [True, False, True, True])
        h.fill([True, True, True], True)

>       assert_array_equal(h[True, :].view(), [1, 4])

tests/test_histogram.py:698:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
build/lib.linux-x86_64-3.9/boost_histogram/_internal/hist.py:653: in __getitem__
    indexes = self._compute_commonindex(index)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <[TypeError('(): incompatible function arguments. The following argument types are supported:\n    1. (arg0: boost_his...> int\n\nInvoked with: integer(0, 2, metadata={}, options=none)') raised in repr()] Histogram object at 0x7ff8125bdac0>
index = (True, slice(None, None, None))

    def _compute_commonindex(self, index):
        """
        Takes indices and returns two iterables; one is a tuple or dict of the
        original, Ellipsis expanded index, and the other returns index,
        operation value pairs.
        """
        # Shorten the computations with direct access to raw object
        hist = self._hist

        # Support dict access
        if hasattr(index, "items"):
            indexes = [slice(None)] * hist.rank()
            for k, v in index.items():
                indexes[k] = v

        # Normalize -> h[i] == h[i,]
        else:
            if not isinstance(index, tuple):
                index = (index,)
            # Now a list
            indexes = _expand_ellipsis(index, hist.rank())

        if len(indexes) != hist.rank():
            raise IndexError("Wrong number of indices for histogram")

        # Allow [bh.loc(...)] to work
        for i in range(len(indexes)):
            # Support sum and rebin directly
            if indexes[i] is sum or hasattr(indexes[i], "factor"):
                indexes[i] = slice(None, None, indexes[i])
            # General locators
            elif callable(indexes[i]):
                indexes[i] = indexes[i](self.axes[i])
            elif hasattr(indexes[i], "__index__"):
>               if abs(indexes[i]) >= hist.axis(i).size:
E               TypeError: (): incompatible function arguments. The following argument types are supported:
E                   1. (arg0: boost_histogram._core.axis.integer_none) -> int
E
E               Invoked with: integer(0, 2, metadata={}, options=none)

build/lib.linux-x86_64-3.9/boost_histogram/_internal/hist.py:551: TypeError
_______________________________ test_slice_bool ________________________________

    def test_slice_bool():
        h = bh.Histogram(bh.axis.Boolean())
        h.fill([0, 0, 0, 1, 3, 4, -2])

        assert_array_equal(h.view(), [3, 4])
>       assert_array_equal(h[1:].view(), [4])

tests/test_histogram.py:709:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
build/lib.linux-x86_64-3.9/boost_histogram/_internal/hist.py:683: in __getitem__
    start, stop = self.axes[i]._process_loc(ind.start, ind.stop)
build/lib.linux-x86_64-3.9/boost_histogram/_internal/axis.py:144: in _process_loc
    stop, len(self) + (1 if self._ax.traits_overflow else 0)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <[TypeError('(): incompatible function arguments. The following argument types are supported:\n    1. (arg0: boost_his... -> int\n\nInvoked with: integer(0, 2, metadata={}, options=none)') raised in repr()] Boolean object at 0x7ff812b27b80>

    def __len__(self):
>       return self._ax.size
E       TypeError: (): incompatible function arguments. The following argument types are supported:
E           1. (arg0: boost_histogram._core.axis.integer_none) -> int
E
E       Invoked with: integer(0, 2, metadata={}, options=none)

build/lib.linux-x86_64-3.9/boost_histogram/_internal/axis.py:127: TypeError
_______________________________ test_pickle_bool _______________________________

    def test_pickle_bool():
        a = bh.Histogram(bh.axis.Boolean(), bh.axis.Boolean(metadata={"one": 1}))
        assert isinstance(a, bh.Histogram)

        a.fill([True, True, False, False], [True, False, True, True])
        a.fill([True, True, True], True)

>       assert a[True, True] == 4

tests/test_histogram.py:723:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
build/lib.linux-x86_64-3.9/boost_histogram/_internal/hist.py:653: in __getitem__
    indexes = self._compute_commonindex(index)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <[TypeError('(): incompatible function arguments. The following argument types are supported:\n    1. (arg0: boost_his...> int\n\nInvoked with: integer(0, 2, metadata={}, options=none)') raised in repr()] Histogram object at 0x7ff8125eb700>
index = (True, True)

    def _compute_commonindex(self, index):
        """
        Takes indices and returns two iterables; one is a tuple or dict of the
        original, Ellipsis expanded index, and the other returns index,
        operation value pairs.
        """
        # Shorten the computations with direct access to raw object
        hist = self._hist

        # Support dict access
        if hasattr(index, "items"):
            indexes = [slice(None)] * hist.rank()
            for k, v in index.items():
                indexes[k] = v

        # Normalize -> h[i] == h[i,]
        else:
            if not isinstance(index, tuple):
                index = (index,)
            # Now a list
            indexes = _expand_ellipsis(index, hist.rank())

        if len(indexes) != hist.rank():
            raise IndexError("Wrong number of indices for histogram")

        # Allow [bh.loc(...)] to work
        for i in range(len(indexes)):
            # Support sum and rebin directly
            if indexes[i] is sum or hasattr(indexes[i], "factor"):
                indexes[i] = slice(None, None, indexes[i])
            # General locators
            elif callable(indexes[i]):
                indexes[i] = indexes[i](self.axes[i])
            elif hasattr(indexes[i], "__index__"):
>               if abs(indexes[i]) >= hist.axis(i).size:
E               TypeError: (): incompatible function arguments. The following argument types are supported:
E                   1. (arg0: boost_histogram._core.axis.integer_none) -> int
E
E               Invoked with: integer(0, 2, metadata={}, options=none)

build/lib.linux-x86_64-3.9/boost_histogram/_internal/hist.py:551: TypeError

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions