Skip to content

Commit 6951888

Browse files
committed
doc: update documentation links and improve clarity on API usage
fix: enforce 1-D input requirement for histogram functions and update tests
1 parent afcbaba commit 6951888

7 files changed

Lines changed: 61 additions & 23 deletions

File tree

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,13 @@ uv run pytest
136136

137137
## Documentation
138138

139-
See the [documentation index](docs/index.rst), [API comparison guide](docs/api_comparison.rst), and [demo notebook](docs/demo.ipynb) for the current API reference and usage examples.
139+
Full documentation is hosted at **[khiops.github.io/khisto-python](https://khiops.github.io/khisto-python/)**.
140+
141+
- [API Reference](https://khiops.github.io/khisto-python/array/histogram/index.html) — NumPy-like histogram API
142+
- [Matplotlib Integration](https://khiops.github.io/khisto-python/matplotlib/index.html)`hist` plotting function
143+
- [Core API](https://khiops.github.io/khisto-python/core/index.html) — full access to histogram granularity levels
144+
- [API Comparison](https://khiops.github.io/khisto-python/api_comparison.html) — side-by-side with NumPy and Matplotlib
145+
- [Demo Notebook](https://khiops.github.io/khisto-python/demo.html) — interactive walkthrough
140146

141147
## License
142148

docs/api_comparison.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ Key Differences
197197
- ``bins``, ``stacked``, and ``weights`` raise a ``TypeError``
198198
* - **Multiple datasets**
199199
- Supported
200-
- Sequences are concatenated into one dataset. Sequences of different lengths are not supported.
200+
- Not supported. Only 1-D arrays are accepted.
201201

202202
Usage Comparison
203203
""""""""""""""""

pyproject.toml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,45 @@ license = "BSD-3-Clause-Clear"
77
license-files = ["LICENSE"]
88
requires-python = ">=3.10"
99
dependencies = ["numpy>=2.0"]
10+
authors = [
11+
{name = "Elouen Ginat", email = "elouen.ginat@orange.com"},
12+
]
13+
keywords = [
14+
"histogram",
15+
"binning",
16+
"optimal",
17+
"khiops",
18+
"statistics",
19+
"data-analysis",
20+
"density-estimation",
21+
"distribution",
22+
"numpy",
23+
"matplotlib",
24+
"visualization",
25+
]
26+
classifiers = [
27+
"Development Status :: 4 - Beta",
28+
"Intended Audience :: Developers",
29+
"Intended Audience :: Science/Research",
30+
"License :: OSI Approved :: BSD License",
31+
"Operating System :: OS Independent",
32+
"Programming Language :: Python :: 3",
33+
"Programming Language :: Python :: 3.10",
34+
"Programming Language :: Python :: 3.11",
35+
"Programming Language :: Python :: 3.12",
36+
"Programming Language :: Python :: 3.13",
37+
"Topic :: Scientific/Engineering",
38+
"Topic :: Scientific/Engineering :: Mathematics",
39+
"Topic :: Scientific/Engineering :: Visualization",
40+
"Typing :: Typed",
41+
]
42+
43+
[project.urls]
44+
Homepage = "https://github.com/khiops/khisto-python"
45+
Documentation = "https://khiops.github.io/khisto-python/"
46+
Repository = "https://github.com/khiops/khisto-python"
47+
Issues = "https://github.com/khiops/khisto-python/issues"
48+
Changelog = "https://github.com/khiops/khisto-python/blob/main/CHANGELOG.md"
1049

1150
[tool.khiops]
1251
khiops-version = "11.0.1-a.3"

src/khisto/array/histogram/api.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def histogram(
6262
Parameters
6363
----------
6464
a : array_like
65-
Input data. The histogram is computed over the flattened array.
65+
Input data. Must be 1-dimensional.
6666
range : tuple of (float, float), optional
6767
The lower and upper range of the bins. Values outside the range are
6868
ignored. If not provided, the range is ``(a.min(), a.max())``.
@@ -105,7 +105,13 @@ def histogram(
105105
histograms for large-scale data sets. Computational Statistics & Data
106106
Analysis, 180:0-0, 2023.
107107
"""
108-
arr = np.asarray(a, dtype=np.float64).flatten()
108+
arr = np.asarray(a, dtype=np.float64)
109+
110+
if arr.ndim != 1:
111+
raise ValueError(
112+
f"Expected 1-D array, got {arr.ndim}-D array instead. "
113+
"Reshape your data or flatten it before calling histogram."
114+
)
109115

110116
if max_bins is not None and max_bins <= 0:
111117
raise ValueError("max_bins must be a positive integer or None.")

src/khisto/matplotlib/hist.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,8 @@ def hist(
7272
7373
Parameters
7474
----------
75-
x : array_like or sequence of array_like
76-
Input data. Nested arrays are concatenated and histogrammed as a
77-
single dataset. This behavior is different from Matplotlib's hist, which treats a sequence of
78-
arrays as multiple datasets and plots them separately.
75+
x : array_like
76+
Input data. Must be 1-dimensional.
7977
range : tuple of (float, float), optional
8078
Lower and upper range of the bins. Values outside the range are
8179
ignored.

tests/array/test_histogram.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,8 @@ def test_bin_edges_length(self, normal_data):
172172
hist, bin_edges = histogram(normal_data)
173173
assert len(bin_edges) == len(hist) + 1
174174

175-
def test_2d_array_flattening(self):
176-
"""Test that 2D arrays are flattened."""
175+
def test_2d_array_raises(self):
176+
"""Test that 2D arrays raise ValueError."""
177177
data_2d = np.array([[1, 2, 3], [4, 5, 6]])
178-
hist, bin_edges = histogram(data_2d)
179-
180-
# Should process all 6 values
181-
assert np.sum(hist) == 6
178+
with pytest.raises(ValueError, match="Expected 1-D array"):
179+
histogram(data_2d)

tests/plot/test_matplotlib_histogram.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -151,15 +151,6 @@ def test_reverse_cumulative_frequency_histogram(self, normal_data):
151151
assert np.isclose(n[0], len(normal_data))
152152
plt.close(fig)
153153

154-
def test_sequence_of_arrays_is_combined(self, normal_data):
155-
"""Test that sequences of arrays are combined into one histogram."""
156-
fig, ax = plt.subplots()
157-
datasets = [normal_data[:500], normal_data[500:]]
158-
n, bins, patches = hist(datasets, ax=ax)
159-
160-
assert np.sum(n) == len(normal_data)
161-
plt.close(fig)
162-
163154
def test_unsupported_bins_parameter(self, normal_data):
164155
"""Test that bins raises a clear error message."""
165156
fig, ax = plt.subplots()

0 commit comments

Comments
 (0)