diff --git a/docs/notebooks/test_nested.ipynb b/docs/notebooks/test_nested.ipynb deleted file mode 100644 index 5d61aa4..0000000 --- a/docs/notebooks/test_nested.ipynb +++ /dev/null @@ -1,1069 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "/Users/wilsonbb/lincc/nested/dropna/nested-pandas/.conda/bin/python\n" - ] - } - ], - "source": [ - "!which python" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "/Users/wilsonbb/lincc/nested/dropna/nested-pandas/.conda/bin/pip\n" - ] - } - ], - "source": [ - "!which pip" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [], - "source": [ - "import nested_pandas as npd\n", - "import pandas as pd" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [], - "source": [ - "data = pd.DataFrame({\n", - " 'a': [],#1, 2, 3],\n", - " 'b': []#,4, float('nan'), 6],\n", - "})#, index=pd.Series([0, 1, 2], name='idx'))\n", - "\n", - "packed = pd.DataFrame({\n", - " 'c': [],#7, 8, 9, 10, 11, 12],\n", - " 'd': [],#10, float('nan'), 12, float('nan'), 13, 14],\n", - "})#, index=pd.Series([0, 0, 1, 1, 2, 2], name='idx'))" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "RangeIndex(start=0, stop=3, step=1)\n", - "RangeIndex(start=0, stop=6, step=1)\n", - "RangeIndex(start=0, stop=3, step=1)\n", - "RangeIndex(start=0, stop=3, step=1)\n", - "Index([0, 1, 2], dtype='int64')\n" - ] - } - ], - "source": [ - "nf = npd.NestedFrame(data=data)\n", - "nf = nf.add_nested(packed, name='packed')\n", - "\n", - "print(data.index)\n", - "print(packed.index)\n", - "print(nf.index)\n", - "print(nf.packed.index)\n", - "print(nf.packed.nest.to_flat().index)" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
cd
idx
0710.0
08NaN
1912.0
110NaN
21113.0
21214.0
\n", - "
" - ], - "text/plain": [ - " c d\n", - "idx \n", - "0 7 10.0\n", - "0 8 NaN\n", - "1 9 12.0\n", - "1 10 NaN\n", - "2 11 13.0\n", - "2 12 14.0" - ] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "packed" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
ab
idx
014.0
12NaN
236.0
\n", - "
" - ], - "text/plain": [ - " a b\n", - "idx \n", - "0 1 4.0\n", - "1 2 NaN\n", - "2 3 6.0" - ] - }, - "execution_count": 7, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "nf = npd.NestedFrame(data=data)\n", - "nf" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [], - "source": [ - "nf = nf.add_nested(packed, name='packed')" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "['packed']\n", - "Index(['a', 'b', 'packed'], dtype='object')\n" - ] - } - ], - "source": [ - "print(nf.nested_columns)\n", - "print(nf.columns)" - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
cd
0710.0
08NaN
1912.0
110NaN
21113.0
21214.0
\n", - "
" - ], - "text/plain": [ - " c d\n", - "0 7 10.0\n", - "0 8 NaN\n", - "1 9 12.0\n", - "1 10 NaN\n", - "2 11 13.0\n", - "2 12 14.0" - ] - }, - "execution_count": 10, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "nf.packed.nest.to_flat()" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
abpacked
idx
014.0c d\n", - "0 7 10.0\n", - "1 8 NaN
12NaNc d\n", - "0 9 12.0\n", - "1 10 NaN
236.0c d\n", - "0 11 13.0\n", - "1 12 14.0
\n", - "
" - ], - "text/plain": [ - " a b packed\n", - "idx \n", - "0 1 4.0 c d\n", - "0 7 10.0\n", - "1 8 NaN\n", - "1 2 NaN c d\n", - "0 9 12.0\n", - "1 10 NaN\n", - "2 3 6.0 c d\n", - "0 11 13.0\n", - "1 12 14.0" - ] - }, - "execution_count": 11, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "nf" - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
cd
0710.0
08NaN
1912.0
110NaN
21113.0
21214.0
\n", - "
" - ], - "text/plain": [ - " c d\n", - "0 7 10.0\n", - "0 8 NaN\n", - "1 9 12.0\n", - "1 10 NaN\n", - "2 11 13.0\n", - "2 12 14.0" - ] - }, - "execution_count": 12, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "nf.packed.nest.to_flat()" - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n" - ] - }, - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
abcd
014.0710.0
014.08NaN
12NaN912.0
12NaN10NaN
236.01113.0
236.01214.0
\n", - "
" - ], - "text/plain": [ - " a b c d\n", - "0 1 4.0 7 10.0\n", - "0 1 4.0 8 NaN\n", - "1 2 NaN 9 12.0\n", - "1 2 NaN 10 NaN\n", - "2 3 6.0 11 13.0\n", - "2 3 6.0 12 14.0" - ] - }, - "execution_count": 13, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "full = nf.merge(nf.packed.nest.to_flat(), left_index=True, right_index=True).drop(columns=['packed'])\n", - "print(type(full))\n", - "full" - ] - }, - { - "cell_type": "code", - "execution_count": 17, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
cd
1912.0
110NaN
\n", - "
" - ], - "text/plain": [ - " c d\n", - "1 9 12.0\n", - "1 10 NaN" - ] - }, - "execution_count": 17, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "def func(a, b, c):\n", - " return a + b + c\n", - "\n", - "\n", - "# Figure out that C is a nested column\n", - "output_frame = # define meta\n", - "result = nf.batch(func, 'a', 'b', 'packed.c')\n", - "\n", - "nf.join(result)" - ] - }, - { - "cell_type": "code", - "execution_count": 18, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
abpacked
idx
014.0c d\n", - "0 7 10.0\n", - "1 8 NaN
12NaNc d\n", - "0 9 12.0\n", - "1 10 NaN
236.0c d\n", - "0 11 13.0\n", - "1 12 14.0
\n", - "
" - ], - "text/plain": [ - " a b packed\n", - "idx \n", - "0 1 4.0 c d\n", - "0 7 10.0\n", - "1 8 NaN\n", - "1 2 NaN c d\n", - "0 9 12.0\n", - "1 10 NaN\n", - "2 3 6.0 c d\n", - "0 11 13.0\n", - "1 12 14.0" - ] - }, - "execution_count": 18, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "nf\n", - "\n" - ] - }, - { - "cell_type": "code", - "execution_count": 50, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
cd
1912.0
110NaN
21113.0
21214.0
\n", - "
" - ], - "text/plain": [ - " c d\n", - "1 9 12.0\n", - "1 10 NaN\n", - "2 11 13.0\n", - "2 12 14.0" - ] - }, - "execution_count": 50, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "new_pack = nf.packed.nest.to_flat().query(\"c > 8\")\n", - "new_pack" - ] - }, - { - "cell_type": "code", - "execution_count": 49, - "metadata": {}, - "outputs": [ - { - "ename": "TypeError", - "evalue": "Invalid value '' for dtype nested", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mArrowTypeError\u001b[0m Traceback (most recent call last)", - "File \u001b[0;32m~/lincc/nested/dropna/nested-pandas/.conda/lib/python3.10/site-packages/pandas/core/arrays/arrow/array.py:2051\u001b[0m, in \u001b[0;36mArrowExtensionArray._maybe_convert_setitem_value\u001b[0;34m(self, value)\u001b[0m\n\u001b[1;32m 2050\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[0;32m-> 2051\u001b[0m value \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_box_pa(value, \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_pa_array\u001b[39m.\u001b[39;49mtype)\n\u001b[1;32m 2052\u001b[0m \u001b[39mexcept\u001b[39;00m pa\u001b[39m.\u001b[39mArrowTypeError \u001b[39mas\u001b[39;00m err:\n", - "File \u001b[0;32m~/lincc/nested/dropna/nested-pandas/.conda/lib/python3.10/site-packages/pandas/core/arrays/arrow/array.py:404\u001b[0m, in \u001b[0;36mArrowExtensionArray._box_pa\u001b[0;34m(cls, value, pa_type)\u001b[0m\n\u001b[1;32m 403\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39misinstance\u001b[39m(value, pa\u001b[39m.\u001b[39mScalar) \u001b[39mor\u001b[39;00m \u001b[39mnot\u001b[39;00m is_list_like(value):\n\u001b[0;32m--> 404\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mcls\u001b[39;49m\u001b[39m.\u001b[39;49m_box_pa_scalar(value, pa_type)\n\u001b[1;32m 405\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mcls\u001b[39m\u001b[39m.\u001b[39m_box_pa_array(value, pa_type)\n", - "File \u001b[0;32m~/lincc/nested/dropna/nested-pandas/.conda/lib/python3.10/site-packages/pandas/core/arrays/arrow/array.py:440\u001b[0m, in \u001b[0;36mArrowExtensionArray._box_pa_scalar\u001b[0;34m(cls, value, pa_type)\u001b[0m\n\u001b[1;32m 438\u001b[0m value \u001b[39m=\u001b[39m value\u001b[39m.\u001b[39m_value\n\u001b[0;32m--> 440\u001b[0m pa_scalar \u001b[39m=\u001b[39m pa\u001b[39m.\u001b[39;49mscalar(value, \u001b[39mtype\u001b[39;49m\u001b[39m=\u001b[39;49mpa_type, from_pandas\u001b[39m=\u001b[39;49m\u001b[39mTrue\u001b[39;49;00m)\n\u001b[1;32m 442\u001b[0m \u001b[39mif\u001b[39;00m pa_type \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mNone\u001b[39;00m \u001b[39mand\u001b[39;00m pa_scalar\u001b[39m.\u001b[39mtype \u001b[39m!=\u001b[39m pa_type:\n", - "File \u001b[0;32m~/lincc/nested/dropna/nested-pandas/.conda/lib/python3.10/site-packages/pyarrow/scalar.pxi:1150\u001b[0m, in \u001b[0;36mpyarrow.lib.scalar\u001b[0;34m()\u001b[0m\n", - "File \u001b[0;32m~/lincc/nested/dropna/nested-pandas/.conda/lib/python3.10/site-packages/pyarrow/error.pxi:154\u001b[0m, in \u001b[0;36mpyarrow.lib.pyarrow_internal_check_status\u001b[0;34m()\u001b[0m\n", - "File \u001b[0;32m~/lincc/nested/dropna/nested-pandas/.conda/lib/python3.10/site-packages/pyarrow/error.pxi:91\u001b[0m, in \u001b[0;36mpyarrow.lib.check_status\u001b[0;34m()\u001b[0m\n", - "\u001b[0;31mArrowTypeError\u001b[0m: Could not convert with type NAType: was not a dict, tuple, or recognized null value for conversion to struct type", - "\nThe above exception was the direct cause of the following exception:\n", - "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[49], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m nf\u001b[39m.\u001b[39;49madd_nested(new_pack, name\u001b[39m=\u001b[39;49m\u001b[39m'\u001b[39;49m\u001b[39mpacked\u001b[39;49m\u001b[39m'\u001b[39;49m)\n", - "File \u001b[0;32m~/lincc/nested/dropna/nested-pandas/.conda/lib/python3.10/site-packages/nested_pandas/nestedframe/core.py:60\u001b[0m, in \u001b[0;36mNestedFrame.add_nested\u001b[0;34m(self, nested, name)\u001b[0m\n\u001b[1;32m 58\u001b[0m packed \u001b[39m=\u001b[39m packer\u001b[39m.\u001b[39mpack_flat(nested, name\u001b[39m=\u001b[39mname)\n\u001b[1;32m 59\u001b[0m label \u001b[39m=\u001b[39m packed\u001b[39m.\u001b[39mname\n\u001b[0;32m---> 60\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49massign(\u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49m{\u001b[39mf\u001b[39;49m\u001b[39m\"\u001b[39;49m\u001b[39m{\u001b[39;49;00mlabel\u001b[39m}\u001b[39;49;00m\u001b[39m\"\u001b[39;49m: packed})\n", - "File \u001b[0;32m~/lincc/nested/dropna/nested-pandas/.conda/lib/python3.10/site-packages/pandas/core/frame.py:5226\u001b[0m, in \u001b[0;36mDataFrame.assign\u001b[0;34m(self, **kwargs)\u001b[0m\n\u001b[1;32m 5223\u001b[0m data \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mcopy(deep\u001b[39m=\u001b[39m\u001b[39mNone\u001b[39;00m)\n\u001b[1;32m 5225\u001b[0m \u001b[39mfor\u001b[39;00m k, v \u001b[39min\u001b[39;00m kwargs\u001b[39m.\u001b[39mitems():\n\u001b[0;32m-> 5226\u001b[0m data[k] \u001b[39m=\u001b[39m com\u001b[39m.\u001b[39mapply_if_callable(v, data)\n\u001b[1;32m 5227\u001b[0m \u001b[39mreturn\u001b[39;00m data\n", - "File \u001b[0;32m~/lincc/nested/dropna/nested-pandas/.conda/lib/python3.10/site-packages/pandas/core/frame.py:4299\u001b[0m, in \u001b[0;36mDataFrame.__setitem__\u001b[0;34m(self, key, value)\u001b[0m\n\u001b[1;32m 4296\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_setitem_array([key], value)\n\u001b[1;32m 4297\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[1;32m 4298\u001b[0m \u001b[39m# set column\u001b[39;00m\n\u001b[0;32m-> 4299\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_set_item(key, value)\n", - "File \u001b[0;32m~/lincc/nested/dropna/nested-pandas/.conda/lib/python3.10/site-packages/pandas/core/frame.py:4512\u001b[0m, in \u001b[0;36mDataFrame._set_item\u001b[0;34m(self, key, value)\u001b[0m\n\u001b[1;32m 4502\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m_set_item\u001b[39m(\u001b[39mself\u001b[39m, key, value) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m \u001b[39mNone\u001b[39;00m:\n\u001b[1;32m 4503\u001b[0m \u001b[39m \u001b[39m\u001b[39m\"\"\"\u001b[39;00m\n\u001b[1;32m 4504\u001b[0m \u001b[39m Add series to DataFrame in specified column.\u001b[39;00m\n\u001b[1;32m 4505\u001b[0m \n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 4510\u001b[0m \u001b[39m ensure homogeneity.\u001b[39;00m\n\u001b[1;32m 4511\u001b[0m \u001b[39m \"\"\"\u001b[39;00m\n\u001b[0;32m-> 4512\u001b[0m value, refs \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_sanitize_column(value)\n\u001b[1;32m 4514\u001b[0m \u001b[39mif\u001b[39;00m (\n\u001b[1;32m 4515\u001b[0m key \u001b[39min\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mcolumns\n\u001b[1;32m 4516\u001b[0m \u001b[39mand\u001b[39;00m value\u001b[39m.\u001b[39mndim \u001b[39m==\u001b[39m \u001b[39m1\u001b[39m\n\u001b[1;32m 4517\u001b[0m \u001b[39mand\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39misinstance\u001b[39m(value\u001b[39m.\u001b[39mdtype, ExtensionDtype)\n\u001b[1;32m 4518\u001b[0m ):\n\u001b[1;32m 4519\u001b[0m \u001b[39m# broadcast across multiple columns if necessary\u001b[39;00m\n\u001b[1;32m 4520\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mcolumns\u001b[39m.\u001b[39mis_unique \u001b[39mor\u001b[39;00m \u001b[39misinstance\u001b[39m(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mcolumns, MultiIndex):\n", - "File \u001b[0;32m~/lincc/nested/dropna/nested-pandas/.conda/lib/python3.10/site-packages/pandas/core/frame.py:5250\u001b[0m, in \u001b[0;36mDataFrame._sanitize_column\u001b[0;34m(self, value)\u001b[0m\n\u001b[1;32m 5248\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39misinstance\u001b[39m(value, Series):\n\u001b[1;32m 5249\u001b[0m value \u001b[39m=\u001b[39m Series(value)\n\u001b[0;32m-> 5250\u001b[0m \u001b[39mreturn\u001b[39;00m _reindex_for_setitem(value, \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mindex)\n\u001b[1;32m 5252\u001b[0m \u001b[39mif\u001b[39;00m is_list_like(value):\n\u001b[1;32m 5253\u001b[0m com\u001b[39m.\u001b[39mrequire_length_match(value, \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mindex)\n", - "File \u001b[0;32m~/lincc/nested/dropna/nested-pandas/.conda/lib/python3.10/site-packages/pandas/core/frame.py:12674\u001b[0m, in \u001b[0;36m_reindex_for_setitem\u001b[0;34m(value, index)\u001b[0m\n\u001b[1;32m 12672\u001b[0m \u001b[39m# GH#4107\u001b[39;00m\n\u001b[1;32m 12673\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[0;32m> 12674\u001b[0m reindexed_value \u001b[39m=\u001b[39m value\u001b[39m.\u001b[39;49mreindex(index)\u001b[39m.\u001b[39m_values\n\u001b[1;32m 12675\u001b[0m \u001b[39mexcept\u001b[39;00m \u001b[39mValueError\u001b[39;00m \u001b[39mas\u001b[39;00m err:\n\u001b[1;32m 12676\u001b[0m \u001b[39m# raised in MultiIndex.from_tuples, see test_insert_error_msmgs\u001b[39;00m\n\u001b[1;32m 12677\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mnot\u001b[39;00m value\u001b[39m.\u001b[39mindex\u001b[39m.\u001b[39mis_unique:\n\u001b[1;32m 12678\u001b[0m \u001b[39m# duplicate axis\u001b[39;00m\n", - "File \u001b[0;32m~/lincc/nested/dropna/nested-pandas/.conda/lib/python3.10/site-packages/pandas/core/series.py:5144\u001b[0m, in \u001b[0;36mSeries.reindex\u001b[0;34m(self, index, axis, method, copy, level, fill_value, limit, tolerance)\u001b[0m\n\u001b[1;32m 5127\u001b[0m \u001b[39m@doc\u001b[39m(\n\u001b[1;32m 5128\u001b[0m NDFrame\u001b[39m.\u001b[39mreindex, \u001b[39m# type: ignore[has-type]\u001b[39;00m\n\u001b[1;32m 5129\u001b[0m klass\u001b[39m=\u001b[39m_shared_doc_kwargs[\u001b[39m\"\u001b[39m\u001b[39mklass\u001b[39m\u001b[39m\"\u001b[39m],\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 5142\u001b[0m tolerance\u001b[39m=\u001b[39m\u001b[39mNone\u001b[39;00m,\n\u001b[1;32m 5143\u001b[0m ) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m Series:\n\u001b[0;32m-> 5144\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39msuper\u001b[39;49m()\u001b[39m.\u001b[39;49mreindex(\n\u001b[1;32m 5145\u001b[0m index\u001b[39m=\u001b[39;49mindex,\n\u001b[1;32m 5146\u001b[0m method\u001b[39m=\u001b[39;49mmethod,\n\u001b[1;32m 5147\u001b[0m copy\u001b[39m=\u001b[39;49mcopy,\n\u001b[1;32m 5148\u001b[0m level\u001b[39m=\u001b[39;49mlevel,\n\u001b[1;32m 5149\u001b[0m fill_value\u001b[39m=\u001b[39;49mfill_value,\n\u001b[1;32m 5150\u001b[0m limit\u001b[39m=\u001b[39;49mlimit,\n\u001b[1;32m 5151\u001b[0m tolerance\u001b[39m=\u001b[39;49mtolerance,\n\u001b[1;32m 5152\u001b[0m )\n", - "File \u001b[0;32m~/lincc/nested/dropna/nested-pandas/.conda/lib/python3.10/site-packages/pandas/core/generic.py:5607\u001b[0m, in \u001b[0;36mNDFrame.reindex\u001b[0;34m(self, labels, index, columns, axis, method, copy, level, fill_value, limit, tolerance)\u001b[0m\n\u001b[1;32m 5604\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_reindex_multi(axes, copy, fill_value)\n\u001b[1;32m 5606\u001b[0m \u001b[39m# perform the reindex on the axes\u001b[39;00m\n\u001b[0;32m-> 5607\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_reindex_axes(\n\u001b[1;32m 5608\u001b[0m axes, level, limit, tolerance, method, fill_value, copy\n\u001b[1;32m 5609\u001b[0m )\u001b[39m.\u001b[39m__finalize__(\u001b[39mself\u001b[39m, method\u001b[39m=\u001b[39m\u001b[39m\"\u001b[39m\u001b[39mreindex\u001b[39m\u001b[39m\"\u001b[39m)\n", - "File \u001b[0;32m~/lincc/nested/dropna/nested-pandas/.conda/lib/python3.10/site-packages/pandas/core/generic.py:5635\u001b[0m, in \u001b[0;36mNDFrame._reindex_axes\u001b[0;34m(self, axes, level, limit, tolerance, method, fill_value, copy)\u001b[0m\n\u001b[1;32m 5630\u001b[0m new_index, indexer \u001b[39m=\u001b[39m ax\u001b[39m.\u001b[39mreindex(\n\u001b[1;32m 5631\u001b[0m labels, level\u001b[39m=\u001b[39mlevel, limit\u001b[39m=\u001b[39mlimit, tolerance\u001b[39m=\u001b[39mtolerance, method\u001b[39m=\u001b[39mmethod\n\u001b[1;32m 5632\u001b[0m )\n\u001b[1;32m 5634\u001b[0m axis \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_get_axis_number(a)\n\u001b[0;32m-> 5635\u001b[0m obj \u001b[39m=\u001b[39m obj\u001b[39m.\u001b[39;49m_reindex_with_indexers(\n\u001b[1;32m 5636\u001b[0m {axis: [new_index, indexer]},\n\u001b[1;32m 5637\u001b[0m fill_value\u001b[39m=\u001b[39;49mfill_value,\n\u001b[1;32m 5638\u001b[0m copy\u001b[39m=\u001b[39;49mcopy,\n\u001b[1;32m 5639\u001b[0m allow_dups\u001b[39m=\u001b[39;49m\u001b[39mFalse\u001b[39;49;00m,\n\u001b[1;32m 5640\u001b[0m )\n\u001b[1;32m 5641\u001b[0m \u001b[39m# If we've made a copy once, no need to make another one\u001b[39;00m\n\u001b[1;32m 5642\u001b[0m copy \u001b[39m=\u001b[39m \u001b[39mFalse\u001b[39;00m\n", - "File \u001b[0;32m~/lincc/nested/dropna/nested-pandas/.conda/lib/python3.10/site-packages/pandas/core/generic.py:5683\u001b[0m, in \u001b[0;36mNDFrame._reindex_with_indexers\u001b[0;34m(self, reindexers, fill_value, copy, allow_dups)\u001b[0m\n\u001b[1;32m 5680\u001b[0m indexer \u001b[39m=\u001b[39m ensure_platform_int(indexer)\n\u001b[1;32m 5682\u001b[0m \u001b[39m# TODO: speed up on homogeneous DataFrame objects (see _reindex_multi)\u001b[39;00m\n\u001b[0;32m-> 5683\u001b[0m new_data \u001b[39m=\u001b[39m new_data\u001b[39m.\u001b[39;49mreindex_indexer(\n\u001b[1;32m 5684\u001b[0m index,\n\u001b[1;32m 5685\u001b[0m indexer,\n\u001b[1;32m 5686\u001b[0m axis\u001b[39m=\u001b[39;49mbaxis,\n\u001b[1;32m 5687\u001b[0m fill_value\u001b[39m=\u001b[39;49mfill_value,\n\u001b[1;32m 5688\u001b[0m allow_dups\u001b[39m=\u001b[39;49mallow_dups,\n\u001b[1;32m 5689\u001b[0m copy\u001b[39m=\u001b[39;49mcopy,\n\u001b[1;32m 5690\u001b[0m )\n\u001b[1;32m 5691\u001b[0m \u001b[39m# If we've made a copy once, no need to make another one\u001b[39;00m\n\u001b[1;32m 5692\u001b[0m copy \u001b[39m=\u001b[39m \u001b[39mFalse\u001b[39;00m\n", - "File \u001b[0;32m~/lincc/nested/dropna/nested-pandas/.conda/lib/python3.10/site-packages/pandas/core/internals/managers.py:680\u001b[0m, in \u001b[0;36mBaseBlockManager.reindex_indexer\u001b[0;34m(self, new_axis, indexer, axis, fill_value, allow_dups, copy, only_slice, use_na_proxy)\u001b[0m\n\u001b[1;32m 677\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mIndexError\u001b[39;00m(\u001b[39m\"\u001b[39m\u001b[39mRequested axis not found in manager\u001b[39m\u001b[39m\"\u001b[39m)\n\u001b[1;32m 679\u001b[0m \u001b[39mif\u001b[39;00m axis \u001b[39m==\u001b[39m \u001b[39m0\u001b[39m:\n\u001b[0;32m--> 680\u001b[0m new_blocks \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_slice_take_blocks_ax0(\n\u001b[1;32m 681\u001b[0m indexer,\n\u001b[1;32m 682\u001b[0m fill_value\u001b[39m=\u001b[39;49mfill_value,\n\u001b[1;32m 683\u001b[0m only_slice\u001b[39m=\u001b[39;49monly_slice,\n\u001b[1;32m 684\u001b[0m use_na_proxy\u001b[39m=\u001b[39;49muse_na_proxy,\n\u001b[1;32m 685\u001b[0m )\n\u001b[1;32m 686\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[1;32m 687\u001b[0m new_blocks \u001b[39m=\u001b[39m [\n\u001b[1;32m 688\u001b[0m blk\u001b[39m.\u001b[39mtake_nd(\n\u001b[1;32m 689\u001b[0m indexer,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 695\u001b[0m \u001b[39mfor\u001b[39;00m blk \u001b[39min\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mblocks\n\u001b[1;32m 696\u001b[0m ]\n", - "File \u001b[0;32m~/lincc/nested/dropna/nested-pandas/.conda/lib/python3.10/site-packages/pandas/core/internals/managers.py:773\u001b[0m, in \u001b[0;36mBaseBlockManager._slice_take_blocks_ax0\u001b[0;34m(self, slice_or_indexer, fill_value, only_slice, use_na_proxy, ref_inplace_op)\u001b[0m\n\u001b[1;32m 770\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[1;32m 771\u001b[0m bp \u001b[39m=\u001b[39m BlockPlacement(\u001b[39mslice\u001b[39m(\u001b[39m0\u001b[39m, sllen))\n\u001b[1;32m 772\u001b[0m \u001b[39mreturn\u001b[39;00m [\n\u001b[0;32m--> 773\u001b[0m blk\u001b[39m.\u001b[39;49mtake_nd(\n\u001b[1;32m 774\u001b[0m slobj,\n\u001b[1;32m 775\u001b[0m axis\u001b[39m=\u001b[39;49m\u001b[39m0\u001b[39;49m,\n\u001b[1;32m 776\u001b[0m new_mgr_locs\u001b[39m=\u001b[39;49mbp,\n\u001b[1;32m 777\u001b[0m fill_value\u001b[39m=\u001b[39;49mfill_value,\n\u001b[1;32m 778\u001b[0m )\n\u001b[1;32m 779\u001b[0m ]\n\u001b[1;32m 781\u001b[0m \u001b[39mif\u001b[39;00m sl_type \u001b[39m==\u001b[39m \u001b[39m\"\u001b[39m\u001b[39mslice\u001b[39m\u001b[39m\"\u001b[39m:\n\u001b[1;32m 782\u001b[0m blknos \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mblknos[slobj]\n", - "File \u001b[0;32m~/lincc/nested/dropna/nested-pandas/.conda/lib/python3.10/site-packages/pandas/core/internals/blocks.py:1307\u001b[0m, in \u001b[0;36mBlock.take_nd\u001b[0;34m(self, indexer, axis, new_mgr_locs, fill_value)\u001b[0m\n\u001b[1;32m 1304\u001b[0m allow_fill \u001b[39m=\u001b[39m \u001b[39mTrue\u001b[39;00m\n\u001b[1;32m 1306\u001b[0m \u001b[39m# Note: algos.take_nd has upcast logic similar to coerce_to_target_dtype\u001b[39;00m\n\u001b[0;32m-> 1307\u001b[0m new_values \u001b[39m=\u001b[39m algos\u001b[39m.\u001b[39;49mtake_nd(\n\u001b[1;32m 1308\u001b[0m values, indexer, axis\u001b[39m=\u001b[39;49maxis, allow_fill\u001b[39m=\u001b[39;49mallow_fill, fill_value\u001b[39m=\u001b[39;49mfill_value\n\u001b[1;32m 1309\u001b[0m )\n\u001b[1;32m 1311\u001b[0m \u001b[39m# Called from three places in managers, all of which satisfy\u001b[39;00m\n\u001b[1;32m 1312\u001b[0m \u001b[39m# these assertions\u001b[39;00m\n\u001b[1;32m 1313\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39misinstance\u001b[39m(\u001b[39mself\u001b[39m, ExtensionBlock):\n\u001b[1;32m 1314\u001b[0m \u001b[39m# NB: in this case, the 'axis' kwarg will be ignored in the\u001b[39;00m\n\u001b[1;32m 1315\u001b[0m \u001b[39m# algos.take_nd call above.\u001b[39;00m\n", - "File \u001b[0;32m~/lincc/nested/dropna/nested-pandas/.conda/lib/python3.10/site-packages/pandas/core/array_algos/take.py:114\u001b[0m, in \u001b[0;36mtake_nd\u001b[0;34m(arr, indexer, axis, fill_value, allow_fill)\u001b[0m\n\u001b[1;32m 109\u001b[0m arr \u001b[39m=\u001b[39m cast(\u001b[39m\"\u001b[39m\u001b[39mNDArrayBackedExtensionArray\u001b[39m\u001b[39m\"\u001b[39m, arr)\n\u001b[1;32m 110\u001b[0m \u001b[39mreturn\u001b[39;00m arr\u001b[39m.\u001b[39mtake(\n\u001b[1;32m 111\u001b[0m indexer, fill_value\u001b[39m=\u001b[39mfill_value, allow_fill\u001b[39m=\u001b[39mallow_fill, axis\u001b[39m=\u001b[39maxis\n\u001b[1;32m 112\u001b[0m )\n\u001b[0;32m--> 114\u001b[0m \u001b[39mreturn\u001b[39;00m arr\u001b[39m.\u001b[39;49mtake(indexer, fill_value\u001b[39m=\u001b[39;49mfill_value, allow_fill\u001b[39m=\u001b[39;49mallow_fill)\n\u001b[1;32m 116\u001b[0m arr \u001b[39m=\u001b[39m np\u001b[39m.\u001b[39masarray(arr)\n\u001b[1;32m 117\u001b[0m \u001b[39mreturn\u001b[39;00m _take_nd_ndarray(arr, indexer, axis, fill_value, allow_fill)\n", - "File \u001b[0;32m~/lincc/nested/dropna/nested-pandas/.conda/lib/python3.10/site-packages/pandas/core/arrays/arrow/array.py:1302\u001b[0m, in \u001b[0;36mArrowExtensionArray.take\u001b[0;34m(self, indices, allow_fill, fill_value)\u001b[0m\n\u001b[1;32m 1299\u001b[0m \u001b[39m# TODO: ArrowNotImplementedError: Function fill_null has no\u001b[39;00m\n\u001b[1;32m 1300\u001b[0m \u001b[39m# kernel matching input types (array[string], scalar[string])\u001b[39;00m\n\u001b[1;32m 1301\u001b[0m result \u001b[39m=\u001b[39m \u001b[39mtype\u001b[39m(\u001b[39mself\u001b[39m)(result)\n\u001b[0;32m-> 1302\u001b[0m result[fill_mask] \u001b[39m=\u001b[39m fill_value\n\u001b[1;32m 1303\u001b[0m \u001b[39mreturn\u001b[39;00m result\n\u001b[1;32m 1304\u001b[0m \u001b[39m# return type(self)(pc.fill_null(result, pa.scalar(fill_value)))\u001b[39;00m\n\u001b[1;32m 1305\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[1;32m 1306\u001b[0m \u001b[39m# Nothing to fill\u001b[39;00m\n", - "File \u001b[0;32m~/lincc/nested/dropna/nested-pandas/.conda/lib/python3.10/site-packages/nested_pandas/series/ext_array.py:169\u001b[0m, in \u001b[0;36mNestedExtensionArray.__setitem__\u001b[0;34m(self, key, value)\u001b[0m\n\u001b[1;32m 167\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m__setitem__\u001b[39m(\u001b[39mself\u001b[39m, key, value) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m \u001b[39mNone\u001b[39;00m:\n\u001b[1;32m 168\u001b[0m value \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_convert_df_value_to_pa(value, \u001b[39mtype\u001b[39m\u001b[39m=\u001b[39m\u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_dtype\u001b[39m.\u001b[39mpyarrow_dtype)\n\u001b[0;32m--> 169\u001b[0m \u001b[39msuper\u001b[39;49m()\u001b[39m.\u001b[39;49m\u001b[39m__setitem__\u001b[39;49m(key, value)\n", - "File \u001b[0;32m~/lincc/nested/dropna/nested-pandas/.conda/lib/python3.10/site-packages/pandas/core/arrays/arrow/array.py:1828\u001b[0m, in \u001b[0;36mArrowExtensionArray.__setitem__\u001b[0;34m(self, key, value)\u001b[0m\n\u001b[1;32m 1825\u001b[0m key \u001b[39m=\u001b[39m key[\u001b[39m0\u001b[39m]\n\u001b[1;32m 1827\u001b[0m key \u001b[39m=\u001b[39m check_array_indexer(\u001b[39mself\u001b[39m, key)\n\u001b[0;32m-> 1828\u001b[0m value \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_maybe_convert_setitem_value(value)\n\u001b[1;32m 1830\u001b[0m \u001b[39mif\u001b[39;00m com\u001b[39m.\u001b[39mis_null_slice(key):\n\u001b[1;32m 1831\u001b[0m \u001b[39m# fast path (GH50248)\u001b[39;00m\n\u001b[1;32m 1832\u001b[0m data \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_if_else(\u001b[39mTrue\u001b[39;00m, value, \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_pa_array)\n", - "File \u001b[0;32m~/lincc/nested/dropna/nested-pandas/.conda/lib/python3.10/site-packages/pandas/core/arrays/arrow/array.py:2054\u001b[0m, in \u001b[0;36mArrowExtensionArray._maybe_convert_setitem_value\u001b[0;34m(self, value)\u001b[0m\n\u001b[1;32m 2052\u001b[0m \u001b[39mexcept\u001b[39;00m pa\u001b[39m.\u001b[39mArrowTypeError \u001b[39mas\u001b[39;00m err:\n\u001b[1;32m 2053\u001b[0m msg \u001b[39m=\u001b[39m \u001b[39mf\u001b[39m\u001b[39m\"\u001b[39m\u001b[39mInvalid value \u001b[39m\u001b[39m'\u001b[39m\u001b[39m{\u001b[39;00m\u001b[39mstr\u001b[39m(value)\u001b[39m}\u001b[39;00m\u001b[39m'\u001b[39m\u001b[39m for dtype \u001b[39m\u001b[39m{\u001b[39;00m\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mdtype\u001b[39m}\u001b[39;00m\u001b[39m\"\u001b[39m\n\u001b[0;32m-> 2054\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mTypeError\u001b[39;00m(msg) \u001b[39mfrom\u001b[39;00m \u001b[39merr\u001b[39;00m\n\u001b[1;32m 2055\u001b[0m \u001b[39mreturn\u001b[39;00m value\n", - "\u001b[0;31mTypeError\u001b[0m: Invalid value '' for dtype nested" - ] - } - ], - "source": [ - "nf.add_nested(new_pack, name='packed')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": 28, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "idx\n", - "0 c d\n", - "0 7 10.0\n", - "1 8 NaN\n", - "1 c d\n", - "0 9 12.0\n", - "1 10 NaN\n", - "2 c d\n", - "0 11 13.0\n", - "1 12 14.0\n", - "Name: packed, dtype: nested" - ] - }, - "execution_count": 28, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "nf.packed" - ] - }, - { - "cell_type": "code", - "execution_count": 42, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 42, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "nf.packed.nest" - ] - }, - { - "cell_type": "code", - "execution_count": 56, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "Index([0, 0, 1, 1, 2, 2], dtype='int64')" - ] - }, - "execution_count": 56, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "nf.packed.nest.to_flat()" - ] - }, - { - "cell_type": "code", - "execution_count": 52, - "metadata": {}, - "outputs": [ - { - "ename": "KeyError", - "evalue": "'idx'", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[52], line 5\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mcalc_median\u001b[39m(x):\n\u001b[1;32m 2\u001b[0m \u001b[39mreturn\u001b[39;00m x\u001b[39m.\u001b[39mmedian()\n\u001b[0;32m----> 5\u001b[0m result \u001b[39m=\u001b[39m nf\u001b[39m.\u001b[39;49mpacked\u001b[39m.\u001b[39;49mnest\u001b[39m.\u001b[39;49mto_flat()\u001b[39m.\u001b[39;49mgroupby(\u001b[39m'\u001b[39;49m\u001b[39midx\u001b[39;49m\u001b[39m'\u001b[39;49m)\u001b[39m.\u001b[39mapply(calc_median)\n", - "File \u001b[0;32m~/lincc/nested/dropna/nested-pandas/.conda/lib/python3.10/site-packages/pandas/core/frame.py:9170\u001b[0m, in \u001b[0;36mDataFrame.groupby\u001b[0;34m(self, by, axis, level, as_index, sort, group_keys, observed, dropna)\u001b[0m\n\u001b[1;32m 9167\u001b[0m \u001b[39mif\u001b[39;00m level \u001b[39mis\u001b[39;00m \u001b[39mNone\u001b[39;00m \u001b[39mand\u001b[39;00m by \u001b[39mis\u001b[39;00m \u001b[39mNone\u001b[39;00m:\n\u001b[1;32m 9168\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mTypeError\u001b[39;00m(\u001b[39m\"\u001b[39m\u001b[39mYou have to supply one of \u001b[39m\u001b[39m'\u001b[39m\u001b[39mby\u001b[39m\u001b[39m'\u001b[39m\u001b[39m and \u001b[39m\u001b[39m'\u001b[39m\u001b[39mlevel\u001b[39m\u001b[39m'\u001b[39m\u001b[39m\"\u001b[39m)\n\u001b[0;32m-> 9170\u001b[0m \u001b[39mreturn\u001b[39;00m DataFrameGroupBy(\n\u001b[1;32m 9171\u001b[0m obj\u001b[39m=\u001b[39;49m\u001b[39mself\u001b[39;49m,\n\u001b[1;32m 9172\u001b[0m keys\u001b[39m=\u001b[39;49mby,\n\u001b[1;32m 9173\u001b[0m axis\u001b[39m=\u001b[39;49maxis,\n\u001b[1;32m 9174\u001b[0m level\u001b[39m=\u001b[39;49mlevel,\n\u001b[1;32m 9175\u001b[0m as_index\u001b[39m=\u001b[39;49mas_index,\n\u001b[1;32m 9176\u001b[0m sort\u001b[39m=\u001b[39;49msort,\n\u001b[1;32m 9177\u001b[0m group_keys\u001b[39m=\u001b[39;49mgroup_keys,\n\u001b[1;32m 9178\u001b[0m observed\u001b[39m=\u001b[39;49mobserved,\n\u001b[1;32m 9179\u001b[0m dropna\u001b[39m=\u001b[39;49mdropna,\n\u001b[1;32m 9180\u001b[0m )\n", - "File \u001b[0;32m~/lincc/nested/dropna/nested-pandas/.conda/lib/python3.10/site-packages/pandas/core/groupby/groupby.py:1329\u001b[0m, in \u001b[0;36mGroupBy.__init__\u001b[0;34m(self, obj, keys, axis, level, grouper, exclusions, selection, as_index, sort, group_keys, observed, dropna)\u001b[0m\n\u001b[1;32m 1326\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mdropna \u001b[39m=\u001b[39m dropna\n\u001b[1;32m 1328\u001b[0m \u001b[39mif\u001b[39;00m grouper \u001b[39mis\u001b[39;00m \u001b[39mNone\u001b[39;00m:\n\u001b[0;32m-> 1329\u001b[0m grouper, exclusions, obj \u001b[39m=\u001b[39m get_grouper(\n\u001b[1;32m 1330\u001b[0m obj,\n\u001b[1;32m 1331\u001b[0m keys,\n\u001b[1;32m 1332\u001b[0m axis\u001b[39m=\u001b[39;49maxis,\n\u001b[1;32m 1333\u001b[0m level\u001b[39m=\u001b[39;49mlevel,\n\u001b[1;32m 1334\u001b[0m sort\u001b[39m=\u001b[39;49msort,\n\u001b[1;32m 1335\u001b[0m observed\u001b[39m=\u001b[39;49m\u001b[39mFalse\u001b[39;49;00m \u001b[39mif\u001b[39;49;00m observed \u001b[39mis\u001b[39;49;00m lib\u001b[39m.\u001b[39;49mno_default \u001b[39melse\u001b[39;49;00m observed,\n\u001b[1;32m 1336\u001b[0m dropna\u001b[39m=\u001b[39;49m\u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mdropna,\n\u001b[1;32m 1337\u001b[0m )\n\u001b[1;32m 1339\u001b[0m \u001b[39mif\u001b[39;00m observed \u001b[39mis\u001b[39;00m lib\u001b[39m.\u001b[39mno_default:\n\u001b[1;32m 1340\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39many\u001b[39m(ping\u001b[39m.\u001b[39m_passed_categorical \u001b[39mfor\u001b[39;00m ping \u001b[39min\u001b[39;00m grouper\u001b[39m.\u001b[39mgroupings):\n", - "File \u001b[0;32m~/lincc/nested/dropna/nested-pandas/.conda/lib/python3.10/site-packages/pandas/core/groupby/grouper.py:1043\u001b[0m, in \u001b[0;36mget_grouper\u001b[0;34m(obj, key, axis, level, sort, observed, validate, dropna)\u001b[0m\n\u001b[1;32m 1041\u001b[0m in_axis, level, gpr \u001b[39m=\u001b[39m \u001b[39mFalse\u001b[39;00m, gpr, \u001b[39mNone\u001b[39;00m\n\u001b[1;32m 1042\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[0;32m-> 1043\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mKeyError\u001b[39;00m(gpr)\n\u001b[1;32m 1044\u001b[0m \u001b[39melif\u001b[39;00m \u001b[39misinstance\u001b[39m(gpr, Grouper) \u001b[39mand\u001b[39;00m gpr\u001b[39m.\u001b[39mkey \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mNone\u001b[39;00m:\n\u001b[1;32m 1045\u001b[0m \u001b[39m# Add key to exclusions\u001b[39;00m\n\u001b[1;32m 1046\u001b[0m exclusions\u001b[39m.\u001b[39madd(gpr\u001b[39m.\u001b[39mkey)\n", - "\u001b[0;31mKeyError\u001b[0m: 'idx'" - ] - } - ], - "source": [ - "def calc_median(x):\n", - " return x.median()\n", - "\n", - "\n", - "result = nf.packed.nest.to_flat().groupby('idx').apply(calc_median)\n", - "\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "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.10.14" - }, - "orig_nbformat": 4 - }, - "nbformat": 4, - "nbformat_minor": 2 -}