Skip to content

Commit d89c0e9

Browse files
committed
fix: faster picking when no slices are made
1 parent 71f9568 commit d89c0e9

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

docs/CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# What's new in boost-histogram
22

3-
## Version 1.1
3+
## Version 1.2
44

5-
### Version 1.1.1
5+
### Version 1.2.0
66

77
#### User changes
88
* Python 3.10 officially supported, with wheels.
@@ -11,6 +11,7 @@
1111

1212
#### Bug fixes
1313
* Support custom setters on AxesTuple subclasses. [#627][]
14+
* Faster picking if slices are not also used [#645][]
1415
* Throw an error when an AxesTuple setter is the wrong length (inspired by zip strict in Python 3.10) [#627][]
1516
* Fix error thrown on comparison with axis and non-axis object [#631][]
1617
* Static typing no longer thinks `storage=` is required [#604][]
@@ -26,8 +27,11 @@
2627
[#627]: https://github.com/scikit-hep/boost-histogram/pull/627
2728
[#631]: https://github.com/scikit-hep/boost-histogram/pull/631
2829
[#636]: https://github.com/scikit-hep/boost-histogram/pull/636
30+
[#645]: https://github.com/scikit-hep/boost-histogram/pull/645
2931
[#647]: https://github.com/scikit-hep/boost-histogram/pull/647
3032

33+
## Version 1.1
34+
3135
### Version 1.1.0
3236

3337
#### User changes

src/boost_histogram/_internal/hist.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -841,8 +841,16 @@ def __getitem__( # noqa: C901
841841
assert isinstance(stop, int)
842842
slices.append(_core.algorithm.slice_and_rebin(i, start, stop, merge))
843843

844-
logger.debug("Reduce with %s", slices)
845-
reduced = self._hist.reduce(*slices)
844+
if slices:
845+
logger.debug("Reduce with %s", slices)
846+
reduced = self._hist.reduce(*slices)
847+
elif pick_set or pick_each or integrations:
848+
# Can avoid a copy in these cases, will be copied anyway
849+
logger.debug("Reduce is empty, but picking or slicing, so no copy needed")
850+
reduced = self._hist
851+
else:
852+
logger.debug("Reduce is empty, just making a copy")
853+
reduced = copy.copy(self._hist)
846854

847855
if pick_set:
848856
warnings.warn(

0 commit comments

Comments
 (0)