Skip to content

Commit

Permalink
uproot fails
Browse files Browse the repository at this point in the history
  • Loading branch information
APN-Pucky committed Nov 16, 2024
1 parent d1e36c8 commit db2fdcf
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ import babyyoda.yoda as yoda
| [histoprint](https://github.com/scikit-hep/histoprint) || [histoprint histo1d](examples/interface/histoprint/histo1d.ipynb) |
| [mplhep](https://github.com/scikit-hep/mplhep) || [mplhep histo1d](examples/interface/mplhep/histo1d.ipynb), [mplhep histo2d](examples/interface/mplhep/histo2d.ipynb) |
| [plothist](https://github.com/scikit-hep/plothist) || Does not support UHI/PlottableProtocol, only boost-histogram |
| [uproot](https://github.com/scikit-hep/uproot) | | |
| [uproot](https://github.com/scikit-hep/uproot) | | WIP: [uproot histo1d](examples/interface/uproot/histo1d.ipynb) |
| [hist](https://github.com/scikit-hep/hist) || |
| [boost-histogram](https://github.com/scikit-hep/boost-histogram) || |
| [cuda-histogram](https://github.com/scikit-hep/cuda-histogram) || |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"cells": [],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 5
}
94 changes: 94 additions & 0 deletions examples/interface/uproot/histo1d.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "904cf963-49fd-499f-96e4-877e80ee2794",
"metadata": {},
"outputs": [],
"source": [
"import uproot\n",
"\n",
"import babyyoda"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "e41b5f20-f7ea-469d-b284-6998d4d644cc",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'/': GROGU_HISTO1D_V3(d_annotations={'Path': '/', 'Title': 'test', 'Type': 'Histo1D'}, d_key='/', d_edges=[0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0], d_bins=[GROGU_HISTO1D_V3.Bin(d_sumw=3.0, d_sumw2=3.0, d_sumwx=-5.0, d_sumwx2=9.0, d_numentries=3.0), GROGU_HISTO1D_V3.Bin(d_sumw=0.0, d_sumw2=0.0, d_sumwx=0.0, d_sumwx2=0.0, d_numentries=0.0), GROGU_HISTO1D_V3.Bin(d_sumw=1.0, d_sumw2=1.0, d_sumwx=1.0, d_sumwx2=1.0, d_numentries=1.0), GROGU_HISTO1D_V3.Bin(d_sumw=2.0, d_sumw2=2.0, d_sumwx=4.0, d_sumwx2=8.0, d_numentries=2.0), GROGU_HISTO1D_V3.Bin(d_sumw=3.0, d_sumw2=3.0, d_sumwx=9.0, d_sumwx2=27.0, d_numentries=3.0), GROGU_HISTO1D_V3.Bin(d_sumw=4.0, d_sumw2=4.0, d_sumwx=16.0, d_sumwx2=64.0, d_numentries=4.0), GROGU_HISTO1D_V3.Bin(d_sumw=5.0, d_sumw2=5.0, d_sumwx=25.0, d_sumwx2=125.0, d_numentries=5.0), GROGU_HISTO1D_V3.Bin(d_sumw=6.0, d_sumw2=6.0, d_sumwx=36.0, d_sumwx2=216.0, d_numentries=6.0), GROGU_HISTO1D_V3.Bin(d_sumw=7.0, d_sumw2=7.0, d_sumwx=49.0, d_sumwx2=343.0, d_numentries=7.0), GROGU_HISTO1D_V3.Bin(d_sumw=8.0, d_sumw2=8.0, d_sumwx=64.0, d_sumwx2=512.0, d_numentries=8.0), GROGU_HISTO1D_V3.Bin(d_sumw=9.0, d_sumw2=9.0, d_sumwx=81.0, d_sumwx2=729.0, d_numentries=9.0), GROGU_HISTO1D_V3.Bin(d_sumw=21.0, d_sumw2=21.0, d_sumwx=221.0, d_sumwx2=2331.0, d_numentries=21.0)])}"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"h = babyyoda.read(\"../../../tests/test_histo1d_v3.yoda\")\n",
"h"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "64acf269-ff90-4915-be00-4a1cd368592d",
"metadata": {},
"outputs": [
{
"ename": "AttributeError",
"evalue": "'list' object has no attribute 'edges'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[4], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m uproot\u001b[38;5;241m.\u001b[39mrecreate(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mnew-file.root\u001b[39m\u001b[38;5;124m\"\u001b[39m) \u001b[38;5;28;01mas\u001b[39;00m file:\n\u001b[0;32m----> 2\u001b[0m \u001b[43mfile\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mhist\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m \u001b[38;5;241m=\u001b[39m h[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m/\u001b[39m\u001b[38;5;124m'\u001b[39m]\n",
"File \u001b[0;32m/usr/lib/python3.13/site-packages/uproot/writing/writable.py:984\u001b[0m, in \u001b[0;36mWritableDirectory.__setitem__\u001b[0;34m(self, where, what)\u001b[0m\n\u001b[1;32m 982\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_file\u001b[38;5;241m.\u001b[39msink\u001b[38;5;241m.\u001b[39mclosed:\n\u001b[1;32m 983\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcannot write data to a closed file\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m--> 984\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mupdate\u001b[49m\u001b[43m(\u001b[49m\u001b[43m{\u001b[49m\u001b[43mwhere\u001b[49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mwhat\u001b[49m\u001b[43m}\u001b[49m\u001b[43m)\u001b[49m\n",
"File \u001b[0;32m/usr/lib/python3.13/site-packages/uproot/writing/writable.py:1553\u001b[0m, in \u001b[0;36mWritableDirectory.update\u001b[0;34m(self, pairs, **more_pairs)\u001b[0m\n\u001b[1;32m 1550\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m item \u001b[38;5;129;01min\u001b[39;00m path:\n\u001b[1;32m 1551\u001b[0m directory \u001b[38;5;241m=\u001b[39m directory[item]\n\u001b[0;32m-> 1553\u001b[0m \u001b[43muproot\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mwriting\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43midentify\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43madd_to_directory\u001b[49m\u001b[43m(\u001b[49m\u001b[43mv\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mname\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mdirectory\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstreamers\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 1555\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_file\u001b[38;5;241m.\u001b[39m_cascading\u001b[38;5;241m.\u001b[39mstreamers\u001b[38;5;241m.\u001b[39mupdate_streamers(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_file\u001b[38;5;241m.\u001b[39msink, streamers)\n",
"File \u001b[0;32m/usr/lib/python3.13/site-packages/uproot/writing/identify.py:155\u001b[0m, in \u001b[0;36madd_to_directory\u001b[0;34m(obj, name, directory, streamers)\u001b[0m\n\u001b[1;32m 152\u001b[0m tree\u001b[38;5;241m.\u001b[39mextend(data)\n\u001b[1;32m 154\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m--> 155\u001b[0m writable \u001b[38;5;241m=\u001b[39m \u001b[43mto_writable\u001b[49m\u001b[43m(\u001b[49m\u001b[43mobj\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 157\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m rawstreamer \u001b[38;5;129;01min\u001b[39;00m writable\u001b[38;5;241m.\u001b[39mclass_rawstreamers:\n\u001b[1;32m 158\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(rawstreamer, \u001b[38;5;28mtuple\u001b[39m):\n",
"File \u001b[0;32m/usr/lib/python3.13/site-packages/uproot/writing/identify.py:336\u001b[0m, in \u001b[0;36mto_writable\u001b[0;34m(obj)\u001b[0m\n\u001b[1;32m 328\u001b[0m fEntries \u001b[38;5;241m=\u001b[39m data\u001b[38;5;241m.\u001b[39msum()\n\u001b[1;32m 330\u001b[0m \u001b[38;5;66;03m# convert all axes in one list comprehension\u001b[39;00m\n\u001b[1;32m 331\u001b[0m axes \u001b[38;5;241m=\u001b[39m [\n\u001b[1;32m 332\u001b[0m to_TAxis(\n\u001b[1;32m 333\u001b[0m fName\u001b[38;5;241m=\u001b[39mdefault_name,\n\u001b[1;32m 334\u001b[0m fTitle\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mgetattr\u001b[39m(axis, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mlabel\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;28mgetattr\u001b[39m(obj, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mname\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m\"\u001b[39m)),\n\u001b[1;32m 335\u001b[0m fNbins\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mlen\u001b[39m(axis),\n\u001b[0;32m--> 336\u001b[0m fXmin\u001b[38;5;241m=\u001b[39m\u001b[43maxis\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43medges\u001b[49m[\u001b[38;5;241m0\u001b[39m],\n\u001b[1;32m 337\u001b[0m fXmax\u001b[38;5;241m=\u001b[39maxis\u001b[38;5;241m.\u001b[39medges[\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m1\u001b[39m],\n\u001b[1;32m 338\u001b[0m fXbins\u001b[38;5;241m=\u001b[39m_fXbins_maybe_regular(axis, boost_histogram),\n\u001b[1;32m 339\u001b[0m fLabels\u001b[38;5;241m=\u001b[39m_fLabels_maybe_categorical(axis, boost_histogram),\n\u001b[1;32m 340\u001b[0m )\n\u001b[1;32m 341\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m axis, default_name \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mzip\u001b[39m(obj\u001b[38;5;241m.\u001b[39maxes, [\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mxaxis\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124myaxis\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mzaxis\u001b[39m\u001b[38;5;124m\"\u001b[39m])\n\u001b[1;32m 342\u001b[0m ]\n\u001b[1;32m 344\u001b[0m \u001b[38;5;66;03m# make TH1, TH2, TH3 types independently\u001b[39;00m\n\u001b[1;32m 345\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(axes) \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m1\u001b[39m:\n",
"\u001b[0;31mAttributeError\u001b[0m: 'list' object has no attribute 'edges'"
]
}
],
"source": [
"with uproot.recreate(\"new-file.root\") as file:\n",
" file[\"hist\"] = h[\"/\"]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d820e196-5681-40ce-8cc2-1089226006a3",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.13.0"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Binary file added examples/interface/uproot/new-file.root
Binary file not shown.

0 comments on commit db2fdcf

Please sign in to comment.