diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 6109c10..c2cb24f 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -3,8 +3,12 @@ Changelog ========= -* Fix type hints of function :func:`~core.aggregatelevel` -* Switch from black to ruff for formatting and update pre-commit versions +v0.4.0 (2023-12-12) +------------------------------------------------------------ +* **BREAKING** :mod:`accessors` is imported implicitly. User code does not need to + import it any longer :pull:`45` +* Fix type hints of function :func:`~core.aggregatelevel` :pull:`44` +* Switch from black to ruff for formatting and update pre-commit versions :pull:`43` v0.3.1 (2023-09-18) ------------------------------------------------------------ diff --git a/docs/notebooks/introduction.ipynb b/docs/notebooks/introduction.ipynb index 8ec700f..18b2d1d 100644 --- a/docs/notebooks/introduction.ipynb +++ b/docs/notebooks/introduction.ipynb @@ -348,6 +348,7 @@ "source": [ "from pandas_indexing.datasets import remindhighre_power\n", "\n", + "\n", "df = remindhighre_power()\n", "df.head()" ] @@ -371,7 +372,6 @@ "2. convenience accessors that are hooking into pandas as extensions, like\n", " \n", " ```python\n", - " import pandas_indexing.accessors\n", " df.pix.assign(unit=\"Mt CO2e/yr)\n", " ```\n", "\n", @@ -403,6 +403,7 @@ "source": [ "from pandas_indexing.core import describelevel\n", "\n", + "\n", "describelevel(df) # or: df.idx" ] }, @@ -432,8 +433,6 @@ } ], "source": [ - "import pandas_indexing.accessors\n", - "\n", "df.idx" ] }, @@ -468,7 +467,7 @@ "metadata": {}, "outputs": [], "source": [ - "from pandas_indexing import ismatch, isin # no .idx equivalents" + "from pandas_indexing import isin, ismatch # no .idx equivalents" ] }, { @@ -1518,6 +1517,7 @@ "source": [ "from pandas_indexing import extractlevel, formatlevel\n", "\n", + "\n", "splitdf = extractlevel(df, variable=\"Secondary Energy|{carrier}|{fuel}\", drop=True)\n", "# or: df.pix.extract(variable=\"Secondary Energy|{carrier}|{fuel}\")\n", "splitdf" @@ -2712,6 +2712,7 @@ "source": [ "from pandas_indexing import semijoin\n", "\n", + "\n", "semijoin(\n", " fossil_series, idx, how=\"right\"\n", ") # or: fossil_series.pix.semijoin(idx, how=\"right\")" @@ -2795,6 +2796,7 @@ "source": [ "from pandas_indexing import projectlevel\n", "\n", + "\n", "simple_fossil_series = projectlevel(fossil_series, [\"variable\", \"year\"])\n", "# or: fossil_series.pix.project([\"variable\", \"year\"])\n", "simple_fossil_series" @@ -3714,6 +3716,7 @@ "source": [ "from pandas_indexing import assignlevel\n", "\n", + "\n", "assignlevel(df, variable=\"Updated|\" + projectlevel(df.index, \"variable\"), unit=\"bla\")\n", "# or: df.pix.assign(variable=df.index.pix.project(\"variable\"), unit=\"bla\")" ] @@ -4585,6 +4588,7 @@ "source": [ "from pandas_indexing import formatlevel\n", "\n", + "\n", "formatlevel(df, variable=\"Updated|{variable}\", unit=\"bla\")\n", "# or: df.pix.format(variable=...)" ] @@ -5518,6 +5522,7 @@ "source": [ "from pandas_indexing import uniquelevel\n", "\n", + "\n", "uniquelevel(df, \"variable\")\n", "# or: df.pix.unique(\"variable\")\n", "# or in vanilla pandas: df.index.unique(\"variable\")" @@ -5591,31 +5596,30 @@ { "data": { "text/plain": [ - "variable year \n", - "Coal 2030 182.0149\n", - " 2040 1.0729\n", - " 2050 0.5029\n", - " 2060 0.1836\n", - "Gas 2030 1584.4033\n", - " 2040 1289.4777\n", - " 2050 562.8482\n", - " 2060 349.9091\n", - "Nuclear 2030 275.5920\n", - " 2040 214.4376\n", - " 2050 156.7766\n", - " 2060 92.0667\n", - "2030 Coal 182.0149\n", - "2040 Coal 1.0729\n", - "2050 Coal 0.5029\n", - "2060 Coal 0.1836\n", - "2030 Gas 1584.4033\n", - "2040 Gas 1289.4777\n", - "2050 Gas 562.8482\n", - "2060 Gas 349.9091\n", - "2030 Nuclear 275.5920\n", - "2040 Nuclear 214.4376\n", - "2050 Nuclear 156.7766\n", - "2060 Nuclear 92.0667\n", + "Coal 2030 182.0149\n", + " 2040 1.0729\n", + " 2050 0.5029\n", + " 2060 0.1836\n", + "Gas 2030 1584.4033\n", + " 2040 1289.4777\n", + " 2050 562.8482\n", + " 2060 349.9091\n", + "Nuclear 2030 275.5920\n", + " 2040 214.4376\n", + " 2050 156.7766\n", + " 2060 92.0667\n", + "2030 Coal 182.0149\n", + "2040 Coal 1.0729\n", + "2050 Coal 0.5029\n", + "2060 Coal 0.1836\n", + "2030 Gas 1584.4033\n", + "2040 Gas 1289.4777\n", + "2050 Gas 562.8482\n", + "2060 Gas 349.9091\n", + "2030 Nuclear 275.5920\n", + "2040 Nuclear 214.4376\n", + "2050 Nuclear 156.7766\n", + "2060 Nuclear 92.0667\n", "dtype: float64" ] }, @@ -5695,10 +5699,47 @@ "execution_count": 31, "id": "ef1d54c6", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "variable year\n", + "Coal 2030 182.0149\n", + " 2040 1.0729\n", + " 2050 0.5029\n", + " 2060 0.1836\n", + "Gas 2030 1584.4033\n", + " 2040 1289.4777\n", + " 2050 562.8482\n", + " 2060 349.9091\n", + "Nuclear 2030 275.5920\n", + " 2040 214.4376\n", + " 2050 156.7766\n", + " 2060 92.0667\n", + "Coal 2030 182.0149\n", + " 2040 1.0729\n", + " 2050 0.5029\n", + " 2060 0.1836\n", + "Gas 2030 1584.4033\n", + " 2040 1289.4777\n", + " 2050 562.8482\n", + " 2060 349.9091\n", + "Nuclear 2030 275.5920\n", + " 2040 214.4376\n", + " 2050 156.7766\n", + " 2060 92.0667\n", + "dtype: float64" + ] + }, + "execution_count": 31, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "from pandas_indexing import concat\n", "\n", + "\n", "concat([simple_fossil_series, simple_fossil_series.swaplevel()])" ] }, @@ -5722,7 +5763,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 32, "id": "5b7cb7db", "metadata": {}, "outputs": [ @@ -5744,7 +5785,7 @@ " names=['model', 'scenario', 'variable'])" ] }, - "execution_count": 33, + "execution_count": 32, "metadata": {}, "output_type": "execute_result" } @@ -5755,7 +5796,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 33, "id": "5b7cb7db", "metadata": {}, "outputs": [ @@ -5878,7 +5919,7 @@ "11 REMIND-MAgPIE 2.1-4.3 DeepElec_SSP2_HighRE_Budg900 Nuclear" ] }, - "execution_count": 34, + "execution_count": 33, "metadata": {}, "output_type": "execute_result" } diff --git a/src/pandas_indexing/__init__.py b/src/pandas_indexing/__init__.py index c9cc6d6..669043c 100644 --- a/src/pandas_indexing/__init__.py +++ b/src/pandas_indexing/__init__.py @@ -5,7 +5,7 @@ from importlib.metadata import version as _version -from . import core, datasets +from . import accessors, core, datasets from .arithmetics import add, divide, multiply, subtract from .core import ( aggregatelevel, diff --git a/tests/test_accessors.py b/tests/test_accessors.py index 633d757..28c1e8e 100644 --- a/tests/test_accessors.py +++ b/tests/test_accessors.py @@ -9,8 +9,6 @@ from pandas import DataFrame, Index, MultiIndex from pandas.testing import assert_frame_equal, assert_index_equal, assert_series_equal -import pandas_indexing.accessors # noqa: F401 - def test_assign_index(midx: MultiIndex): """