@@ -88,15 +88,15 @@ class HistogramResult:
8888
8989 Attributes
9090 ----------
91- lower_bound : NDArray[np.float64]
91+ lower_bounds : NDArray[np.float64]
9292 Lower bounds of each bin.
93- upper_bound : NDArray[np.float64]
93+ upper_bounds : NDArray[np.float64]
9494 Upper bounds of each bin.
95- frequency : NDArray[np.int64]
95+ frequencies : NDArray[np.int64]
9696 Count of values in each bin.
97- probability : NDArray[np.float64]
97+ probabilities : NDArray[np.float64]
9898 Probability of each bin (frequency / total).
99- density : NDArray[np.float64]
99+ densities : NDArray[np.float64]
100100 Density of each bin (probability / bin_width).
101101 is_best : bool
102102 Whether this histogram is the optimal one.
@@ -114,11 +114,11 @@ class HistogramResult:
114114 Number of empty intervals in this histogram.
115115 """
116116
117- lower_bound : NDArray [np .float64 ]
118- upper_bound : NDArray [np .float64 ]
119- frequency : NDArray [np .int64 ]
120- probability : NDArray [np .float64 ]
121- density : NDArray [np .float64 ]
117+ lower_bounds : NDArray [np .float64 ]
118+ upper_bounds : NDArray [np .float64 ]
119+ frequencies : NDArray [np .int64 ]
120+ probabilities : NDArray [np .float64 ]
121+ densities : NDArray [np .float64 ]
122122 is_best : bool = False
123123 granularity : int = 0
124124 level : float = 0.0
@@ -130,31 +130,31 @@ class HistogramResult:
130130 @property
131131 def bin_edges (self ) -> NDArray [np .float64 ]:
132132 """Return bin edges array (n_bins + 1 values)."""
133- return np .concatenate ([self .lower_bound , [self .upper_bound [- 1 ]]])
133+ return np .concatenate ([self .lower_bounds , [self .upper_bounds [- 1 ]]])
134134
135135 @property
136136 def bin_widths (self ) -> NDArray [np .float64 ]:
137137 """Return width of each bin."""
138- return self .upper_bound - self .lower_bound
138+ return self .upper_bounds - self .lower_bounds
139139
140140 @property
141141 def bin_centers (self ) -> NDArray [np .float64 ]:
142142 """Return center of each bin."""
143- return (self .lower_bound + self .upper_bound ) / 2
143+ return (self .lower_bounds + self .upper_bounds ) / 2
144144
145145 def __len__ (self ) -> int :
146146 """Return number of bins."""
147- return len (self .lower_bound )
147+ return len (self .lower_bounds )
148148
149149
150150def _to_result (h : _HistogramPayload , ** kwargs : Any ) -> HistogramResult :
151151 """Convert a JSON histogram payload to a HistogramResult."""
152152 return HistogramResult (
153- lower_bound = np .asarray (h .lowerBounds , dtype = np .float64 ),
154- upper_bound = np .asarray (h .upperBounds , dtype = np .float64 ),
155- frequency = np .asarray (h .frequencies , dtype = np .int64 ),
156- probability = np .asarray (h .probabilities , dtype = np .float64 ),
157- density = np .asarray (h .densities , dtype = np .float64 ),
153+ lower_bounds = np .asarray (h .lowerBounds , dtype = np .float64 ),
154+ upper_bounds = np .asarray (h .upperBounds , dtype = np .float64 ),
155+ frequencies = np .asarray (h .frequencies , dtype = np .int64 ),
156+ probabilities = np .asarray (h .probabilities , dtype = np .float64 ),
157+ densities = np .asarray (h .densities , dtype = np .float64 ),
158158 ** kwargs ,
159159 )
160160
@@ -170,11 +170,13 @@ def _format_runtime_error(
170170
171171
172172def _process_histogram_file (
173- temp_output_file : tempfile . _TemporaryFileWrapper [ str ] ,
173+ temp_output_file_path : str ,
174174) -> list [HistogramResult ]:
175175 """Process exploratory JSON generated by khisto CLI."""
176- temp_output_file .seek (0 )
177- khisto_output : _KhistoOutput = _KhistoOutput .from_dict (json .load (temp_output_file ))
176+ with open (temp_output_file_path , "r" ) as temp_output_file :
177+ khisto_output : _KhistoOutput = _KhistoOutput .from_dict (
178+ json .load (temp_output_file )
179+ )
178180
179181 histogram_series = khisto_output .histogramSeries
180182 best_idx = histogram_series .interpretableHistogramNumber - 1
@@ -255,7 +257,7 @@ def compute_histograms(x: np.ndarray) -> list[HistogramResult]:
255257 raise RuntimeError (message ) from e
256258
257259 try :
258- return _process_histogram_file (temp_output_file )
260+ return _process_histogram_file (temp_output_file . name )
259261 except json .JSONDecodeError as e :
260262 message = _format_runtime_error (
261263 "khisto produced invalid JSON output" ,
0 commit comments