You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For my personal use-case I created some helper functions to convert histogram axes to pandas IntervalIndex to help me with creating pandas Series from histograms. It would be nice to use the categories as an Index for category axes. For IntCategory I can obtain them from the mapping, but I don't know whether the category strings for StrCategory axes are public or the mapping of integers to strings is private and impossible to access. Tab-completion and dir didn't show me any method or attribute to access the strings. It's not super important, I can always re-index manually as I know the categories, but would be a nice-to-have.
Just in case someone is interested, below is my hist axis to index and histogram to pd.Series helper code from my personal analysis utils.
defto_tuples(hist_axis: AxisProtocol) ->List[Tuple[float, float]]:
"""Take a hist axis and return a list of bin range tuples each with a lower and upper bin edge."""edges=hist_axis.edgesreturnlist(zip_longest(edges[:-1], edges[1:]))
defto_pd_index(hist_axis: AxisProtocol) ->pd.IntervalIndex:
"""Take a hist axis and return a pandas index"""# TODO: would be nice to just use the categories for category axes returnpd.IntervalIndex.from_tuples(to_tuples(hist_axis))
defto_uncertain_values(histogram: hist.Hist) ->pd.Series:
iflen(histogram.axes) >1:
raiseValueError("Only 1D histograms are supported.")
uncertain_array: npt.NDArray[Any] =np.array(
unc.correlated_values(
histogram.values(),
covariance_mat=np.diag(histogram.variances()),
tags=["histogram statistics"] *len(histogram.axes[0]),
)
)
returnpd.Series(
uncertain_array,
index=to_pd_index(histogram.axes[0]),
)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
For my personal use-case I created some helper functions to convert histogram axes to pandas
IntervalIndex
to help me with creating pandas Series from histograms. It would be nice to use the categories as an Index for category axes. ForIntCategory
I can obtain them from the mapping, but I don't know whether the category strings forStrCategory
axes are public or the mapping of integers to strings is private and impossible to access. Tab-completion anddir
didn't show me any method or attribute to access the strings. It's not super important, I can always re-index manually as I know the categories, but would be a nice-to-have.Just in case someone is interested, below is my hist axis to index and histogram to pd.Series helper code from my personal analysis utils.
Beta Was this translation helpful? Give feedback.
All reactions