Skip to content

Commit 1c278bc

Browse files
committed
refactor: closer to current version of Protocol
1 parent e970d78 commit 1c278bc

File tree

6 files changed

+24
-16
lines changed

6 files changed

+24
-16
lines changed

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ package_dir =
4444
install_requires =
4545
numpy >=1.13.3
4646
typing >= 3.5; python_version < '3.5'
47+
enum34 >= 1.1; python_version < '3.4'
4748

4849
[options.packages.find]
4950
where = src

src/__init__.py

Whitespace-only changes.

src/boost_histogram/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
22
from __future__ import absolute_import, division, print_function
33

4-
from ._internal.hist import Histogram
4+
from ._internal.hist import Histogram, Implementation
55
from . import axis, storage, accumulators, utils, numpy
66
from .tag import loc, rebin, sum, underflow, overflow
77

@@ -37,6 +37,7 @@
3737

3838
__all__ = (
3939
"Histogram",
40+
"Implementation",
4041
"axis",
4142
"storage",
4243
"accumulators",
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# -*- coding: utf-8 -*-
2+
# Try to import Enum, but if it fails, not worth breaking over.
3+
4+
try:
5+
from enum import Enum
6+
except ImportError:
7+
try:
8+
from enum34 import Enum # type: ignore
9+
except ImportError:
10+
Enum = object # type: ignore
11+
12+
13+
class Implementation(str, Enum):
14+
sum = "sum"
15+
mean = "mean"

src/boost_histogram/_internal/hist.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from .storage import Double, Storage
1818
from .utils import cast, register, set_family, MAIN_FAMILY, set_module
1919
from .view import _to_view
20+
from .enum import Implementation
2021

2122

2223
NOTHING = object()
@@ -789,28 +790,18 @@ def project(self, *args):
789790

790791
# Implementation of PlottableHistogram
791792

792-
@property
793-
def weighted(self):
794-
"""
795-
Returns true if the storage has weight information.
796-
797-
:return: bool
798-
"""
799-
view = self.view()
800-
return view.dtype > 0 and hasattr(view, "variance")
801-
802793
@property
803794
def implementation(self):
804795
"""
805796
Returns "count" if this is a normal summing histogram, and "mean" if this is a
806797
mean histogram.
807798
808-
:return: "mean" or "count"
799+
:return: Implementation
809800
"""
810801
if self._storage_type in {_core.storage.mean, _core.storage.weighted_mean}:
811-
return "mean"
802+
return Implementation.mean
812803
else:
813-
return "count"
804+
return Implementation.sum
814805

815806
def values(self, flow=False):
816807
"""
@@ -840,7 +831,7 @@ def variances(self, flow=False):
840831

841832
view = self.view(flow)
842833
if len(view.dtype) == 0:
843-
return view
834+
return None
844835
else:
845836
return view.variance
846837

src/boost_histogram/_internal/traits.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ from typing import Any
22

33

44
class Traits:
5-
underflow
5+
underflow: bool
66
overflow: bool
77
circular: bool
88
growth: bool

0 commit comments

Comments
 (0)