Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: move some things out of internal #975

Merged
merged 16 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions docs/api/boost_histogram.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
boost\_histogram
================

.. automodule:: boost_histogram._internal.hist
:members: Histogram
.. automodule:: boost_histogram
:members:
:undoc-members:
:show-inheritance:

Expand All @@ -18,6 +18,14 @@ boost\_histogram.accumulators
:undoc-members:
:show-inheritance:

boost\_histogram.histogram
==========================

.. automodule:: boost_histogram.histogram
:members:
:undoc-members:
:show-inheritance:

boost\_histogram.numpy
======================

Expand All @@ -42,10 +50,18 @@ boost\_histogram.tag
:undoc-members:
:show-inheritance:

boost\_histogram.version
========================
boost\_histogram.typing
=======================

.. automodule:: boost_histogram.typing
:members:
:undoc-members:
:show-inheritance:

boost\_histogram.view
=====================

.. automodule:: boost_histogram.version
.. automodule:: boost_histogram.view
:members:
:undoc-members:
:show-inheritance:
17 changes: 1 addition & 16 deletions noxfile.py
henryiii marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

import argparse
from pathlib import Path
from typing import Any

import nox
Expand Down Expand Up @@ -98,20 +97,6 @@ def build_api_docs(session: nox.Session) -> None:
"src/boost_histogram",
)

# add API docs of boost_histogram._internal.hist.Histogram after
# the generation step
with Path("docs/api/boost_histogram.rst").open("r+") as f:
lines = f.readlines()
for i in range(len(lines)):
if lines[i] == ".. automodule:: boost_histogram\n":
lines[i] = ".. automodule:: boost_histogram._internal.hist\n"
lines[i + 1] = " :members: Histogram\n"
break

f.truncate(0)
f.seek(0)
f.writelines(lines)


@nox.session
def lint(session: nox.Session) -> None:
Expand All @@ -128,7 +113,7 @@ def pylint(session: nox.Session) -> None:
Run pylint.
"""

session.install("pylint==3.2.*")
session.install("pylint==3.3.*")
session.install("-e.")
session.run("pylint", "boost_histogram", *session.posargs)

Expand Down
13 changes: 10 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -208,22 +208,28 @@ messages_control.disable = [
"too-many-locals",
"too-many-return-statements",
"too-many-statements",
"too-many-positional-arguments",
"wrong-import-position",
]

[tool.ruff.lint]
extend-select = [
"B", # flake8-bugbear
"I", # isort
"ARG", # flake8-unused-arguments
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"EXE", # flake8-executable
"FURB", # refurb
"G", # flake8-logging-format
"I", # isort
"ICN", # flake8-import-conventions
"ISC", # flake8-implicit-str-concat
"PD", # pandas-vet
"PGH", # pygrep-hooks
"PIE", # flake8-pie
"PL", # pylint
"PT", # flake8-pytest-style
"PTH", # flake8-use-pathlib
"PYI", # flake8-pyi
"RET", # flake8-return
"RUF", # Ruff-specific
"SIM", # flake8-simplify
Expand All @@ -237,8 +243,9 @@ ignore = [
"E501", # Line too long
"PT011", "PT013", # Incorrect pytest codes
"ISC001", # Conflicts with the formatter
"PYI034", # We are returning Self, just generic
]
typing-modules = ["boost_histogram._internal.typing"]
typing-modules = ["boost_histogram.typing"]
isort.required-imports = ["from __future__ import annotations"]


Expand Down
Empty file modified scripts/performance_report.py
100644 → 100755
Empty file.
31 changes: 5 additions & 26 deletions src/boost_histogram/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from __future__ import annotations

from . import accumulators, axis, numpy, storage
from ._internal.enum import Kind
from ._internal.hist import Histogram, IndexingExpr
from .histogram import Histogram, IndexingExpr, Kind
from .tag import ( # pylint: disable=redefined-builtin
loc,
overflow,
Expand All @@ -14,21 +13,7 @@
# pylint: disable-next=import-error
from .version import version as __version__

try:
from . import _core
except ImportError as err:
msg = str(err)
if "_core" not in msg:
raise

new_msg = "Did you forget to compile boost-histogram? Use CMake or Setuptools to build, see the readme."
total_msg = f"{msg}\n{new_msg}"

new_exception = type(err)(new_msg, name=err.name, path=err.path)
raise new_exception from err


__all__ = (
__all__ = [
"Histogram",
"IndexingExpr",
"Kind",
Expand All @@ -42,14 +27,8 @@
"storage",
"sum",
"underflow",
)
]


# Support cloudpickle - pybind11 submodules do not have __file__ attributes
# And setting this in C++ causes a segfault
_core.accumulators.__file__ = _core.__file__
_core.algorithm.__file__ = _core.__file__
_core.axis.__file__ = _core.__file__
_core.axis.transform.__file__ = _core.__file__
_core.hist.__file__ = _core.__file__
_core.storage.__file__ = _core.__file__
def __dir__() -> list[str]:
return __all__
2 changes: 0 additions & 2 deletions src/boost_histogram/_core/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
from __future__ import annotations

from . import accumulators, algorithm, axis, hist, storage
38 changes: 17 additions & 21 deletions src/boost_histogram/_core/accumulators.pyi
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
from __future__ import annotations

from typing import Any, Tuple, TypeVar, overload
from typing import Any, overload

from numpy.typing import ArrayLike

T = TypeVar("T", bound="_BaseAccumulator")
from typing_extensions import Self

class _BaseAccumulator:
def __eq__(self, other: Any) -> bool: ...
def __ne__(self, other: Any) -> bool: ...
def __imul__(self: T, other: float) -> T: ...
def __repr__(self) -> str: ...
def __copy__(self: T) -> T: ...
def __deepcopy__(self: T, memo: Any) -> T: ...
def __eq__(self, other: object) -> bool: ...
def __ne__(self, other: object) -> bool: ...
def __imul__(self, other: float) -> Self: ...
def __copy__(self) -> Self: ...
def __deepcopy__(self, memo: Any) -> Self: ...
def _ipython_key_completions_(self) -> tuple[str, ...]: ...

class WeightedSum(_BaseAccumulator):
Expand All @@ -26,8 +22,8 @@ class WeightedSum(_BaseAccumulator):
def value(self) -> float: ...
@property
def variance(self) -> float: ...
def __iadd__(self: T, arg0: float) -> T: ...
def fill(self: T, value: ArrayLike, variance: ArrayLike | None = None) -> T: ...
def __iadd__(self, arg0: float) -> Self: ...
def fill(self, value: ArrayLike, variance: ArrayLike | None = None) -> Self: ...
@staticmethod
def _make(a: ArrayLike, b: ArrayLike) -> WeightedSum: ...
@staticmethod
Expand All @@ -42,8 +38,8 @@ class Sum(_BaseAccumulator):
def __init__(self, value: float) -> None: ...
@property
def value(self) -> float: ...
def __iadd__(self: T, arg0: float) -> T: ...
def fill(self: T, value: ArrayLike) -> T: ...
def __iadd__(self, arg0: float) -> Self: ...
def fill(self, value: ArrayLike) -> Self: ...
@property
def _small(self) -> float: ...
@property
Expand Down Expand Up @@ -71,9 +67,9 @@ class WeightedMean(_BaseAccumulator):
@property
def variance(self) -> float: ...
def __call__(
self: T, value: ArrayLike, *, weight: ArrayLike | None = None
) -> T: ...
def fill(self: T, value: ArrayLike, *, weight: ArrayLike | None = None) -> T: ...
self, value: ArrayLike, *, weight: ArrayLike | None = None
) -> Self: ...
def fill(self, value: ArrayLike, *, weight: ArrayLike | None = None) -> Self: ...
@staticmethod
def _make(
arg0: ArrayLike, arg1: ArrayLike, arg2: ArrayLike, arg3: ArrayLike
Expand All @@ -99,9 +95,9 @@ class Mean(_BaseAccumulator):
@property
def variance(self) -> float: ...
def __call__(
self: T, value: ArrayLike, *, weight: ArrayLike | None = None
) -> T: ...
def fill(self: T, value: ArrayLike, *, weight: ArrayLike | None = None) -> T: ...
self, value: ArrayLike, *, weight: ArrayLike | None = None
) -> Self: ...
def fill(self, value: ArrayLike, *, weight: ArrayLike | None = None) -> Self: ...
@staticmethod
def _make(arg0: ArrayLike, arg1: ArrayLike, arg2: ArrayLike) -> Mean: ...
@staticmethod
Expand Down
3 changes: 0 additions & 3 deletions src/boost_histogram/_core/algorithm.pyi
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
from __future__ import annotations

import enum
import typing

class reduce_command:
iaxis: int
def __repr__(self) -> str: ...

class slice_mode(enum.Enum):
shrink = enum.auto()
Expand Down
16 changes: 6 additions & 10 deletions src/boost_histogram/_core/axis/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
from __future__ import annotations

from typing import Any, Iterable, Iterator, Tuple, TypeVar

import numpy as np
from numpy.typing import ArrayLike
from typing_extensions import Self

from . import transform

T = TypeVar("T", bound="_BaseAxis")

class _BaseAxis:
def __eq__(self, other: Any) -> bool: ...
def __ne__(self, other: Any) -> bool: ...
def __imul__(self: T, other: float) -> T: ...
def __repr__(self) -> str: ...
def __copy__(self: T) -> T: ...
def __deepcopy__(self: T, memo: Any) -> T: ...
def __eq__(self, other: object) -> bool: ...
def __ne__(self, other: object) -> bool: ...
def __imul__(self, other: float) -> Self: ...
def __copy__(self) -> Self: ...
def __deepcopy__(self, memo: Any) -> Self: ...
def _ipython_key_completions_(self) -> tuple[str, ...]: ...
@property
def traits_underflow(self) -> bool: ...
Expand Down
11 changes: 4 additions & 7 deletions src/boost_histogram/_core/axis/transform.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from __future__ import annotations
from typing import Any, Callable

from typing import Any, Callable, TypeVar

T = TypeVar("T", bound="_BaseTransform")
from typing_extensions import Self

def _log_fn(arg0: float) -> float: ...
def _exp_fn(arg0: float) -> float: ...
Expand All @@ -12,9 +10,8 @@ def _sq_fn(arg0: float) -> float: ...
class _BaseTransform:
def forward(self, arg0: float) -> float: ...
def inverse(self, arg0: float) -> float: ...
def __repr__(self) -> str: ...
def __copy__(self: T) -> T: ...
def __deepcopy__(self: T, memo: Any) -> T: ...
def __copy__(self) -> Self: ...
def __deepcopy__(self, memo: Any) -> Self: ...

class id(_BaseTransform): ...
class sqrt(_BaseTransform): ...
Expand Down
Loading
Loading