diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index f6717dd503c9b..7c9ebf7d94173 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -19,7 +19,7 @@ ci:
skip: [pyright, mypy]
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
- rev: v0.5.0
+ rev: v0.6.9
hooks:
- id: ruff
args: [--exit-non-zero-on-fix]
@@ -34,7 +34,7 @@ repos:
- id: ruff-format
exclude: ^scripts|^pandas/tests/frame/test_query_eval.py
- repo: https://github.com/jendrikseipp/vulture
- rev: 'v2.11'
+ rev: 'v2.13'
hooks:
- id: vulture
entry: python scripts/run_vulture.py
@@ -52,7 +52,7 @@ repos:
- id: cython-lint
- id: double-quote-cython-strings
- repo: https://github.com/pre-commit/pre-commit-hooks
- rev: v4.6.0
+ rev: v5.0.0
hooks:
- id: check-case-conflict
- id: check-toml
@@ -90,12 +90,12 @@ repos:
types: [text] # overwrite types: [rst]
types_or: [python, rst]
- repo: https://github.com/sphinx-contrib/sphinx-lint
- rev: v0.9.1
+ rev: v1.0.0
hooks:
- id: sphinx-lint
args: ["--enable", "all", "--disable", "line-too-long"]
- repo: https://github.com/pre-commit/mirrors-clang-format
- rev: v18.1.8
+ rev: v19.1.1
hooks:
- id: clang-format
files: ^pandas/_libs/src|^pandas/_libs/include
diff --git a/doc/source/user_guide/style.ipynb b/doc/source/user_guide/style.ipynb
index daecfce6ecebc..abb7181fc8d72 100644
--- a/doc/source/user_guide/style.ipynb
+++ b/doc/source/user_guide/style.ipynb
@@ -38,19 +38,6 @@
"[concatfunc]: ../reference/api/pandas.io.formats.style.Styler.concat.rst"
]
},
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {
- "nbsphinx": "hidden"
- },
- "outputs": [],
- "source": [
- "import matplotlib.pyplot\n",
- "# We have this here to trigger matplotlib's font cache stuff.\n",
- "# This cell is hidden from the output"
- ]
- },
{
"cell_type": "markdown",
"metadata": {},
@@ -78,17 +65,13 @@
"source": [
"import pandas as pd\n",
"import numpy as np\n",
- "import matplotlib as mpl\n",
"\n",
- "df = pd.DataFrame({\n",
- " \"strings\": [\"Adam\", \"Mike\"],\n",
- " \"ints\": [1, 3],\n",
- " \"floats\": [1.123, 1000.23]\n",
- "})\n",
- "df.style \\\n",
- " .format(precision=3, thousands=\".\", decimal=\",\") \\\n",
- " .format_index(str.upper, axis=1) \\\n",
- " .relabel_index([\"row 1\", \"row 2\"], axis=0)"
+ "df = pd.DataFrame(\n",
+ " {\"strings\": [\"Adam\", \"Mike\"], \"ints\": [1, 3], \"floats\": [1.123, 1000.23]}\n",
+ ")\n",
+ "df.style.format(precision=3, thousands=\".\", decimal=\",\").format_index(\n",
+ " str.upper, axis=1\n",
+ ").relabel_index([\"row 1\", \"row 2\"], axis=0)"
]
},
{
@@ -104,17 +87,21 @@
"metadata": {},
"outputs": [],
"source": [
- "weather_df = pd.DataFrame(np.random.rand(10,2)*5, \n",
- " index=pd.date_range(start=\"2021-01-01\", periods=10),\n",
- " columns=[\"Tokyo\", \"Beijing\"])\n",
+ "weather_df = pd.DataFrame(\n",
+ " np.random.default_rng().random((10, 2)) * 5,\n",
+ " index=pd.date_range(start=\"2021-01-01\", periods=10),\n",
+ " columns=[\"Tokyo\", \"Beijing\"],\n",
+ ")\n",
+ "\n",
"\n",
- "def rain_condition(v): \n",
+ "def rain_condition(v):\n",
" if v < 1.75:\n",
" return \"Dry\"\n",
" elif v < 2.75:\n",
" return \"Rain\"\n",
" return \"Heavy Rain\"\n",
"\n",
+ "\n",
"def make_pretty(styler):\n",
" styler.set_caption(\"Weather Conditions\")\n",
" styler.format(rain_condition)\n",
@@ -122,6 +109,7 @@
" styler.background_gradient(axis=None, vmin=1, vmax=5, cmap=\"YlGnBu\")\n",
" return styler\n",
"\n",
+ "\n",
"weather_df"
]
},
@@ -157,10 +145,8 @@
"metadata": {},
"outputs": [],
"source": [
- "df = pd.DataFrame(np.random.randn(5, 5))\n",
- "df.style \\\n",
- " .hide(subset=[0, 2, 4], axis=0) \\\n",
- " .hide(subset=[0, 2, 4], axis=1)"
+ "df = pd.DataFrame(np.random.default_rng().standard_normal((5, 5)))\n",
+ "df.style.hide(subset=[0, 2, 4], axis=0).hide(subset=[0, 2, 4], axis=1)"
]
},
{
@@ -177,9 +163,9 @@
"outputs": [],
"source": [
"show = [0, 2, 4]\n",
- "df.style \\\n",
- " .hide([row for row in df.index if row not in show], axis=0) \\\n",
- " .hide([col for col in df.columns if col not in show], axis=1)"
+ "df.style.hide([row for row in df.index if row not in show], axis=0).hide(\n",
+ " [col for col in df.columns if col not in show], axis=1\n",
+ ")"
]
},
{
@@ -199,9 +185,9 @@
"metadata": {},
"outputs": [],
"source": [
- "summary_styler = df.agg([\"sum\", \"mean\"]).style \\\n",
- " .format(precision=3) \\\n",
- " .relabel_index([\"Sum\", \"Average\"])\n",
+ "summary_styler = (\n",
+ " df.agg([\"sum\", \"mean\"]).style.format(precision=3).relabel_index([\"Sum\", \"Average\"])\n",
+ ")\n",
"df.style.format(precision=1).concat(summary_styler)"
]
},
@@ -227,9 +213,16 @@
"metadata": {},
"outputs": [],
"source": [
- "df = pd.DataFrame([[38.0, 2.0, 18.0, 22.0, 21, np.nan],[19, 439, 6, 452, 226,232]], \n",
- " index=pd.Index(['Tumour (Positive)', 'Non-Tumour (Negative)'], name='Actual Label:'), \n",
- " columns=pd.MultiIndex.from_product([['Decision Tree', 'Regression', 'Random'],['Tumour', 'Non-Tumour']], names=['Model:', 'Predicted:']))\n",
+ "idx = pd.Index([\"Tumour (Positive)\", \"Non-Tumour (Negative)\"], name=\"Actual Label:\")\n",
+ "cols = pd.MultiIndex.from_product(\n",
+ " [[\"Decision Tree\", \"Regression\", \"Random\"], [\"Tumour\", \"Non-Tumour\"]],\n",
+ " names=[\"Model:\", \"Predicted:\"],\n",
+ ")\n",
+ "df = pd.DataFrame(\n",
+ " [[38.0, 2.0, 18.0, 22.0, 21, np.nan], [19, 439, 6, 452, 226, 232]],\n",
+ " index=idx,\n",
+ " columns=cols,\n",
+ ")\n",
"df.style"
]
},
@@ -242,63 +235,68 @@
"outputs": [],
"source": [
"# Hidden cell to just create the below example: code is covered throughout the guide.\n",
- "s = df.style\\\n",
- " .hide([('Random', 'Tumour'), ('Random', 'Non-Tumour')], axis='columns')\\\n",
- " .format('{:.0f}')\\\n",
- " .set_table_styles([{\n",
- " 'selector': '',\n",
- " 'props': 'border-collapse: separate;'\n",
- " },{\n",
- " 'selector': 'caption',\n",
- " 'props': 'caption-side: bottom; font-size:1.3em;'\n",
- " },{\n",
- " 'selector': '.index_name',\n",
- " 'props': 'font-style: italic; color: darkgrey; font-weight:normal;'\n",
- " },{\n",
- " 'selector': 'th:not(.index_name)',\n",
- " 'props': 'background-color: #000066; color: white;'\n",
- " },{\n",
- " 'selector': 'th.col_heading',\n",
- " 'props': 'text-align: center;'\n",
- " },{\n",
- " 'selector': 'th.col_heading.level0',\n",
- " 'props': 'font-size: 1.5em;'\n",
- " },{\n",
- " 'selector': 'th.col2',\n",
- " 'props': 'border-left: 1px solid white;'\n",
- " },{\n",
- " 'selector': '.col2',\n",
- " 'props': 'border-left: 1px solid #000066;'\n",
- " },{\n",
- " 'selector': 'td',\n",
- " 'props': 'text-align: center; font-weight:bold;'\n",
- " },{\n",
- " 'selector': '.true',\n",
- " 'props': 'background-color: #e6ffe6;'\n",
- " },{\n",
- " 'selector': '.false',\n",
- " 'props': 'background-color: #ffe6e6;'\n",
- " },{\n",
- " 'selector': '.border-red',\n",
- " 'props': 'border: 2px dashed red;'\n",
- " },{\n",
- " 'selector': '.border-green',\n",
- " 'props': 'border: 2px dashed green;'\n",
- " },{\n",
- " 'selector': 'td:hover',\n",
- " 'props': 'background-color: #ffffb3;'\n",
- " }])\\\n",
- " .set_td_classes(pd.DataFrame([['true border-green', 'false', 'true', 'false border-red', '', ''],\n",
- " ['false', 'true', 'false', 'true', '', '']], \n",
- " index=df.index, columns=df.columns))\\\n",
- " .set_caption(\"Confusion matrix for multiple cancer prediction models.\")\\\n",
- " .set_tooltips(pd.DataFrame([['This model has a very strong true positive rate', '', '', \"This model's total number of false negatives is too high\", '', ''],\n",
- " ['', '', '', '', '', '']], \n",
- " index=df.index, columns=df.columns),\n",
- " css_class='pd-tt', props=\n",
- " 'visibility: hidden; position: absolute; z-index: 1; border: 1px solid #000066;'\n",
- " 'background-color: white; color: #000066; font-size: 0.8em;' \n",
- " 'transform: translate(0px, -24px); padding: 0.6em; border-radius: 0.5em;')\n"
+ "s = (\n",
+ " df.style.hide([(\"Random\", \"Tumour\"), (\"Random\", \"Non-Tumour\")], axis=\"columns\")\n",
+ " .format(\"{:.0f}\")\n",
+ " .set_table_styles(\n",
+ " [\n",
+ " {\"selector\": \"\", \"props\": \"border-collapse: separate;\"},\n",
+ " {\"selector\": \"caption\", \"props\": \"caption-side: bottom; font-size:1.3em;\"},\n",
+ " {\n",
+ " \"selector\": \".index_name\",\n",
+ " \"props\": \"font-style: italic; color: darkgrey; font-weight:normal;\",\n",
+ " },\n",
+ " {\n",
+ " \"selector\": \"th:not(.index_name)\",\n",
+ " \"props\": \"background-color: #000066; color: white;\",\n",
+ " },\n",
+ " {\"selector\": \"th.col_heading\", \"props\": \"text-align: center;\"},\n",
+ " {\"selector\": \"th.col_heading.level0\", \"props\": \"font-size: 1.5em;\"},\n",
+ " {\"selector\": \"th.col2\", \"props\": \"border-left: 1px solid white;\"},\n",
+ " {\"selector\": \".col2\", \"props\": \"border-left: 1px solid #000066;\"},\n",
+ " {\"selector\": \"td\", \"props\": \"text-align: center; font-weight:bold;\"},\n",
+ " {\"selector\": \".true\", \"props\": \"background-color: #e6ffe6;\"},\n",
+ " {\"selector\": \".false\", \"props\": \"background-color: #ffe6e6;\"},\n",
+ " {\"selector\": \".border-red\", \"props\": \"border: 2px dashed red;\"},\n",
+ " {\"selector\": \".border-green\", \"props\": \"border: 2px dashed green;\"},\n",
+ " {\"selector\": \"td:hover\", \"props\": \"background-color: #ffffb3;\"},\n",
+ " ]\n",
+ " )\n",
+ " .set_td_classes(\n",
+ " pd.DataFrame(\n",
+ " [\n",
+ " [\"true border-green\", \"false\", \"true\", \"false border-red\", \"\", \"\"],\n",
+ " [\"false\", \"true\", \"false\", \"true\", \"\", \"\"],\n",
+ " ],\n",
+ " index=df.index,\n",
+ " columns=df.columns,\n",
+ " )\n",
+ " )\n",
+ " .set_caption(\"Confusion matrix for multiple cancer prediction models.\")\n",
+ " .set_tooltips(\n",
+ " pd.DataFrame(\n",
+ " [\n",
+ " [\n",
+ " \"This model has a very strong true positive rate\",\n",
+ " \"\",\n",
+ " \"\",\n",
+ " \"This model's total number of false negatives is too high\",\n",
+ " \"\",\n",
+ " \"\",\n",
+ " ],\n",
+ " [\"\", \"\", \"\", \"\", \"\", \"\"],\n",
+ " ],\n",
+ " index=df.index,\n",
+ " columns=df.columns,\n",
+ " ),\n",
+ " css_class=\"pd-tt\",\n",
+ " props=\"visibility: hidden; \"\n",
+ " \"position: absolute; z-index: 1; \"\n",
+ " \"border: 1px solid #000066;\"\n",
+ " \"background-color: white; color: #000066; font-size: 0.8em;\"\n",
+ " \"transform: translate(0px, -24px); padding: 0.6em; border-radius: 0.5em;\",\n",
+ " )\n",
+ ")"
]
},
{
@@ -325,7 +323,9 @@
"metadata": {},
"outputs": [],
"source": [
- "s = df.style.format('{:.0f}').hide([('Random', 'Tumour'), ('Random', 'Non-Tumour')], axis=\"columns\")\n",
+ "s = df.style.format(\"{:.0f}\").hide(\n",
+ " [(\"Random\", \"Tumour\"), (\"Random\", \"Non-Tumour\")], axis=\"columns\"\n",
+ ")\n",
"s"
]
},
@@ -337,8 +337,8 @@
},
"outputs": [],
"source": [
- "# Hidden cell to avoid CSS clashes and latter code upcoding previous formatting \n",
- "s.set_uuid('after_hide')"
+ "# Hidden cell to avoid CSS clashes and latter code upcoding previous formatting\n",
+ "s.set_uuid(\"after_hide\")"
]
},
{
@@ -395,16 +395,16 @@
"outputs": [],
"source": [
"cell_hover = { # for row hover use
instead of \n",
- " 'selector': 'td:hover',\n",
- " 'props': [('background-color', '#ffffb3')]\n",
+ " \"selector\": \"td:hover\",\n",
+ " \"props\": [(\"background-color\", \"#ffffb3\")],\n",
"}\n",
"index_names = {\n",
- " 'selector': '.index_name',\n",
- " 'props': 'font-style: italic; color: darkgrey; font-weight:normal;'\n",
+ " \"selector\": \".index_name\",\n",
+ " \"props\": \"font-style: italic; color: darkgrey; font-weight:normal;\",\n",
"}\n",
"headers = {\n",
- " 'selector': 'th:not(.index_name)',\n",
- " 'props': 'background-color: #000066; color: white;'\n",
+ " \"selector\": \"th:not(.index_name)\",\n",
+ " \"props\": \"background-color: #000066; color: white;\",\n",
"}\n",
"s.set_table_styles([cell_hover, index_names, headers])"
]
@@ -417,8 +417,8 @@
},
"outputs": [],
"source": [
- "# Hidden cell to avoid CSS clashes and latter code upcoding previous formatting \n",
- "s.set_uuid('after_tab_styles1')"
+ "# Hidden cell to avoid CSS clashes and latter code upcoding previous formatting\n",
+ "s.set_uuid(\"after_tab_styles1\")"
]
},
{
@@ -434,11 +434,14 @@
"metadata": {},
"outputs": [],
"source": [
- "s.set_table_styles([\n",
- " {'selector': 'th.col_heading', 'props': 'text-align: center;'},\n",
- " {'selector': 'th.col_heading.level0', 'props': 'font-size: 1.5em;'},\n",
- " {'selector': 'td', 'props': 'text-align: center; font-weight: bold;'},\n",
- "], overwrite=False)"
+ "s.set_table_styles(\n",
+ " [\n",
+ " {\"selector\": \"th.col_heading\", \"props\": \"text-align: center;\"},\n",
+ " {\"selector\": \"th.col_heading.level0\", \"props\": \"font-size: 1.5em;\"},\n",
+ " {\"selector\": \"td\", \"props\": \"text-align: center; font-weight: bold;\"},\n",
+ " ],\n",
+ " overwrite=False,\n",
+ ")"
]
},
{
@@ -449,8 +452,8 @@
},
"outputs": [],
"source": [
- "# Hidden cell to avoid CSS clashes and latter code upcoding previous formatting \n",
- "s.set_uuid('after_tab_styles2')"
+ "# Hidden cell to avoid CSS clashes and latter code upcoding previous formatting\n",
+ "s.set_uuid(\"after_tab_styles2\")"
]
},
{
@@ -468,10 +471,16 @@
"metadata": {},
"outputs": [],
"source": [
- "s.set_table_styles({\n",
- " ('Regression', 'Tumour'): [{'selector': 'th', 'props': 'border-left: 1px solid white'},\n",
- " {'selector': 'td', 'props': 'border-left: 1px solid #000066'}]\n",
- "}, overwrite=False, axis=0)"
+ "s.set_table_styles(\n",
+ " {\n",
+ " (\"Regression\", \"Tumour\"): [\n",
+ " {\"selector\": \"th\", \"props\": \"border-left: 1px solid white\"},\n",
+ " {\"selector\": \"td\", \"props\": \"border-left: 1px solid #000066\"},\n",
+ " ]\n",
+ " },\n",
+ " overwrite=False,\n",
+ " axis=0,\n",
+ ")"
]
},
{
@@ -482,8 +491,8 @@
},
"outputs": [],
"source": [
- "# Hidden cell to avoid CSS clashes and latter code upcoding previous formatting \n",
- "s.set_uuid('xyz01')"
+ "# Hidden cell to avoid CSS clashes and latter code upcoding previous formatting\n",
+ "s.set_uuid(\"xyz01\")"
]
},
{
@@ -508,7 +517,7 @@
"outputs": [],
"source": [
"out = s.set_table_attributes('class=\"my-table-cls\"').to_html()\n",
- "print(out[out.find(' -0.3) else None)\n",
+ "\n",
+ "\n",
+ "s2 = df2.style.map(style_negative, props=\"color:red;\").map(\n",
+ " lambda v: \"opacity: 20%;\" if (v < 0.3) and (v > -0.3) else None\n",
+ ")\n",
"s2"
]
},
@@ -612,8 +629,8 @@
},
"outputs": [],
"source": [
- "# Hidden cell to avoid CSS clashes and latter code upcoding previous formatting \n",
- "s2.set_uuid('after_applymap')"
+ "# Hidden cell to avoid CSS clashes and latter code upcoding previous formatting\n",
+ "s2.set_uuid(\"after_applymap\")"
]
},
{
@@ -629,9 +646,11 @@
"metadata": {},
"outputs": [],
"source": [
- "def highlight_max(s, props=''):\n",
- " return np.where(s == np.nanmax(s.values), props, '')\n",
- "s2.apply(highlight_max, props='color:white;background-color:darkblue', axis=0)"
+ "def highlight_max(s, props=\"\"):\n",
+ " return np.where(s == np.nanmax(s.values), props, \"\")\n",
+ "\n",
+ "\n",
+ "s2.apply(highlight_max, props=\"color:white;background-color:darkblue\", axis=0)"
]
},
{
@@ -642,8 +661,8 @@
},
"outputs": [],
"source": [
- "# Hidden cell to avoid CSS clashes and latter code upcoding previous formatting \n",
- "s2.set_uuid('after_apply')"
+ "# Hidden cell to avoid CSS clashes and latter code upcoding previous formatting\n",
+ "s2.set_uuid(\"after_apply\")"
]
},
{
@@ -659,8 +678,9 @@
"metadata": {},
"outputs": [],
"source": [
- "s2.apply(highlight_max, props='color:white;background-color:pink;', axis=1)\\\n",
- " .apply(highlight_max, props='color:white;background-color:purple', axis=None)"
+ "s2.apply(highlight_max, props=\"color:white;background-color:pink;\", axis=1).apply(\n",
+ " highlight_max, props=\"color:white;background-color:purple\", axis=None\n",
+ ")"
]
},
{
@@ -671,8 +691,8 @@
},
"outputs": [],
"source": [
- "# Hidden cell to avoid CSS clashes and latter code upcoding previous formatting \n",
- "s2.set_uuid('after_apply_again')"
+ "# Hidden cell to avoid CSS clashes and latter code upcoding previous formatting\n",
+ "s2.set_uuid(\"after_apply_again\")"
]
},
{
@@ -713,8 +733,10 @@
"metadata": {},
"outputs": [],
"source": [
- "s2.map_index(lambda v: \"color:pink;\" if v>4 else \"color:darkblue;\", axis=0)\n",
- "s2.apply_index(lambda s: np.where(s.isin([\"A\", \"B\"]), \"color:pink;\", \"color:darkblue;\"), axis=1)"
+ "s2.map_index(lambda v: \"color:pink;\" if v > 4 else \"color:darkblue;\", axis=0)\n",
+ "s2.apply_index(\n",
+ " lambda s: np.where(s.isin([\"A\", \"B\"]), \"color:pink;\", \"color:darkblue;\"), axis=1\n",
+ ")"
]
},
{
@@ -734,11 +756,12 @@
"metadata": {},
"outputs": [],
"source": [
- "s.set_caption(\"Confusion matrix for multiple cancer prediction models.\")\\\n",
- " .set_table_styles([{\n",
- " 'selector': 'caption',\n",
- " 'props': 'caption-side: bottom; font-size:1.25em;'\n",
- " }], overwrite=False)"
+ "s.set_caption(\n",
+ " \"Confusion matrix for multiple cancer prediction models.\"\n",
+ ").set_table_styles(\n",
+ " [{\"selector\": \"caption\", \"props\": \"caption-side: bottom; font-size:1.25em;\"}],\n",
+ " overwrite=False,\n",
+ ")"
]
},
{
@@ -749,8 +772,8 @@
},
"outputs": [],
"source": [
- "# Hidden cell to avoid CSS clashes and latter code upcoding previous formatting \n",
- "s.set_uuid('after_caption')"
+ "# Hidden cell to avoid CSS clashes and latter code upcoding previous formatting\n",
+ "s.set_uuid(\"after_caption\")"
]
},
{
@@ -768,12 +791,24 @@
"metadata": {},
"outputs": [],
"source": [
- "tt = pd.DataFrame([['This model has a very strong true positive rate', \n",
- " \"This model's total number of false negatives is too high\"]], \n",
- " index=['Tumour (Positive)'], columns=df.columns[[0,3]])\n",
- "s.set_tooltips(tt, props='visibility: hidden; position: absolute; z-index: 1; border: 1px solid #000066;'\n",
- " 'background-color: white; color: #000066; font-size: 0.8em;' \n",
- " 'transform: translate(0px, -24px); padding: 0.6em; border-radius: 0.5em;')"
+ "tt = pd.DataFrame(\n",
+ " [\n",
+ " [\n",
+ " \"This model has a very strong true positive rate\",\n",
+ " \"This model's total number of false negatives is too high\",\n",
+ " ]\n",
+ " ],\n",
+ " index=[\"Tumour (Positive)\"],\n",
+ " columns=df.columns[[0, 3]],\n",
+ ")\n",
+ "s.set_tooltips(\n",
+ " tt,\n",
+ " props=\"visibility: hidden; position: absolute; z-index: 1; \"\n",
+ " \"border: 1px solid #000066;\"\n",
+ " \"background-color: white; color: #000066; font-size: 0.8em;\"\n",
+ " \"transform: translate(0px, -24px); padding: 0.6em; \"\n",
+ " \"border-radius: 0.5em;\",\n",
+ ")"
]
},
{
@@ -784,8 +819,8 @@
},
"outputs": [],
"source": [
- "# Hidden cell to avoid CSS clashes and latter code upcoding previous formatting \n",
- "s.set_uuid('after_tooltips')"
+ "# Hidden cell to avoid CSS clashes and latter code upcoding previous formatting\n",
+ "s.set_uuid(\"after_tooltips\")"
]
},
{
@@ -801,14 +836,18 @@
"metadata": {},
"outputs": [],
"source": [
- "s.set_table_styles([ # create internal CSS classes\n",
- " {'selector': '.border-red', 'props': 'border: 2px dashed red;'},\n",
- " {'selector': '.border-green', 'props': 'border: 2px dashed green;'},\n",
- "], overwrite=False)\n",
- "cell_border = pd.DataFrame([['border-green ', ' ', ' ', 'border-red '], \n",
- " [' ', ' ', ' ', ' ']], \n",
- " index=df.index, \n",
- " columns=df.columns[:4])\n",
+ "s.set_table_styles(\n",
+ " [ # create internal CSS classes\n",
+ " {\"selector\": \".border-red\", \"props\": \"border: 2px dashed red;\"},\n",
+ " {\"selector\": \".border-green\", \"props\": \"border: 2px dashed green;\"},\n",
+ " ],\n",
+ " overwrite=False,\n",
+ ")\n",
+ "cell_border = pd.DataFrame(\n",
+ " [[\"border-green \", \" \", \" \", \"border-red \"], [\" \", \" \", \" \", \" \"]],\n",
+ " index=df.index,\n",
+ " columns=df.columns[:4],\n",
+ ")\n",
"s.set_td_classes(cell_color + cell_border)"
]
},
@@ -820,8 +859,8 @@
},
"outputs": [],
"source": [
- "# Hidden cell to avoid CSS clashes and latter code upcoding previous formatting \n",
- "s.set_uuid('after_borders')"
+ "# Hidden cell to avoid CSS clashes and latter code upcoding previous formatting\n",
+ "s.set_uuid(\"after_borders\")"
]
},
{
@@ -847,9 +886,11 @@
"metadata": {},
"outputs": [],
"source": [
- "df3 = pd.DataFrame(np.random.randn(4,4), \n",
- " pd.MultiIndex.from_product([['A', 'B'], ['r1', 'r2']]),\n",
- " columns=['c1','c2','c3','c4'])\n",
+ "df3 = pd.DataFrame(\n",
+ " np.random.default_rng().standard_normal((4, 4)),\n",
+ " pd.MultiIndex.from_product([[\"A\", \"B\"], [\"r1\", \"r2\"]]),\n",
+ " columns=[\"c1\", \"c2\", \"c3\", \"c4\"],\n",
+ ")\n",
"df3"
]
},
@@ -866,9 +907,10 @@
"metadata": {},
"outputs": [],
"source": [
- "slice_ = ['c3', 'c4']\n",
- "df3.style.apply(highlight_max, props='color:red;', axis=0, subset=slice_)\\\n",
- " .set_properties(**{'background-color': '#ffffb3'}, subset=slice_)"
+ "slice_ = [\"c3\", \"c4\"]\n",
+ "df3.style.apply(\n",
+ " highlight_max, props=\"color:red;\", axis=0, subset=slice_\n",
+ ").set_properties(**{\"background-color\": \"#ffffb3\"}, subset=slice_)"
]
},
{
@@ -885,9 +927,10 @@
"outputs": [],
"source": [
"idx = pd.IndexSlice\n",
- "slice_ = idx[idx[:,'r1'], idx['c2':'c4']]\n",
- "df3.style.apply(highlight_max, props='color:red;', axis=0, subset=slice_)\\\n",
- " .set_properties(**{'background-color': '#ffffb3'}, subset=slice_)"
+ "slice_ = idx[idx[:, \"r1\"], idx[\"c2\":\"c4\"]]\n",
+ "df3.style.apply(\n",
+ " highlight_max, props=\"color:red;\", axis=0, subset=slice_\n",
+ ").set_properties(**{\"background-color\": \"#ffffb3\"}, subset=slice_)"
]
},
{
@@ -903,9 +946,10 @@
"metadata": {},
"outputs": [],
"source": [
- "slice_ = idx[idx[:,'r2'], :]\n",
- "df3.style.apply(highlight_max, props='color:red;', axis=1, subset=slice_)\\\n",
- " .set_properties(**{'background-color': '#ffffb3'}, subset=slice_)"
+ "slice_ = idx[idx[:, \"r2\"], :]\n",
+ "df3.style.apply(\n",
+ " highlight_max, props=\"color:red;\", axis=1, subset=slice_\n",
+ ").set_properties(**{\"background-color\": \"#ffffb3\"}, subset=slice_)"
]
},
{
@@ -923,9 +967,10 @@
"metadata": {},
"outputs": [],
"source": [
- "slice_ = idx[idx[(df3['c1'] + df3['c3']) < -2.0], ['c2', 'c4']]\n",
- "df3.style.apply(highlight_max, props='color:red;', axis=1, subset=slice_)\\\n",
- " .set_properties(**{'background-color': '#ffffb3'}, subset=slice_)"
+ "slice_ = idx[idx[(df3[\"c1\"] + df3[\"c3\"]) < -2.0], [\"c2\", \"c4\"]]\n",
+ "df3.style.apply(\n",
+ " highlight_max, props=\"color:red;\", axis=1, subset=slice_\n",
+ ").set_properties(**{\"background-color\": \"#ffffb3\"}, subset=slice_)"
]
},
{
@@ -981,7 +1026,7 @@
"metadata": {},
"outputs": [],
"source": [
- "df4 = pd.DataFrame([[1,2],[3,4]])\n",
+ "df4 = pd.DataFrame([[1, 2], [3, 4]])\n",
"s4 = df4.style"
]
},
@@ -1003,6 +1048,7 @@
"outputs": [],
"source": [
"from pandas.io.formats.style import Styler\n",
+ "\n",
"s4 = Styler(df4, uuid_len=0, cell_ids=False)"
]
},
@@ -1053,7 +1099,7 @@
"metadata": {},
"outputs": [],
"source": [
- "df4.style.set_table_styles([{'selector': 'td.col1', 'props': props}])"
+ "df4.style.set_table_styles([{\"selector\": \"td.col1\", \"props\": props}])"
]
},
{
@@ -1082,9 +1128,11 @@
"metadata": {},
"outputs": [],
"source": [
- "df2.style.apply(highlight_max, props='color:white;background-color:darkblue;', axis=0)\\\n",
- " .apply(highlight_max, props='color:white;background-color:pink;', axis=1)\\\n",
- " .apply(highlight_max, props='color:white;background-color:purple', axis=None)"
+ "df2.style.apply(\n",
+ " highlight_max, props=\"color:white;background-color:darkblue;\", axis=0\n",
+ ").apply(highlight_max, props=\"color:white;background-color:pink;\", axis=1).apply(\n",
+ " highlight_max, props=\"color:white;background-color:purple\", axis=None\n",
+ ")"
]
},
{
@@ -1105,14 +1153,18 @@
"outputs": [],
"source": [
"build = lambda x: pd.DataFrame(x, index=df2.index, columns=df2.columns)\n",
- "cls1 = build(df2.apply(highlight_max, props='cls-1 ', axis=0))\n",
- "cls2 = build(df2.apply(highlight_max, props='cls-2 ', axis=1, result_type='expand').values)\n",
- "cls3 = build(highlight_max(df2, props='cls-3 '))\n",
- "df2.style.set_table_styles([\n",
- " {'selector': '.cls-1', 'props': 'color:white;background-color:darkblue;'},\n",
- " {'selector': '.cls-2', 'props': 'color:white;background-color:pink;'},\n",
- " {'selector': '.cls-3', 'props': 'color:white;background-color:purple;'}\n",
- "]).set_td_classes(cls1 + cls2 + cls3)"
+ "cls1 = build(df2.apply(highlight_max, props=\"cls-1 \", axis=0))\n",
+ "cls2 = build(\n",
+ " df2.apply(highlight_max, props=\"cls-2 \", axis=1, result_type=\"expand\").values\n",
+ ")\n",
+ "cls3 = build(highlight_max(df2, props=\"cls-3 \"))\n",
+ "df2.style.set_table_styles(\n",
+ " [\n",
+ " {\"selector\": \".cls-1\", \"props\": \"color:white;background-color:darkblue;\"},\n",
+ " {\"selector\": \".cls-2\", \"props\": \"color:white;background-color:pink;\"},\n",
+ " {\"selector\": \".cls-3\", \"props\": \"color:white;background-color:purple;\"},\n",
+ " ]\n",
+ ").set_td_classes(cls1 + cls2 + cls3)"
]
},
{
@@ -1152,10 +1204,14 @@
" \"blank\": \"\",\n",
"}\n",
"html = Styler(df4, uuid_len=0, cell_ids=False)\n",
- "html.set_table_styles([{'selector': 'td', 'props': props},\n",
- " {'selector': '.c1', 'props': 'color:green;'},\n",
- " {'selector': '.l0', 'props': 'color:blue;'}],\n",
- " css_class_names=my_css)\n",
+ "html.set_table_styles(\n",
+ " [\n",
+ " {\"selector\": \"td\", \"props\": props},\n",
+ " {\"selector\": \".c1\", \"props\": \"color:green;\"},\n",
+ " {\"selector\": \".l0\", \"props\": \"color:blue;\"},\n",
+ " ],\n",
+ " css_class_names=my_css,\n",
+ ")\n",
"print(html.to_html())"
]
},
@@ -1213,9 +1269,9 @@
"metadata": {},
"outputs": [],
"source": [
- "df2.iloc[0,2] = np.nan\n",
- "df2.iloc[4,3] = np.nan\n",
- "df2.loc[:4].style.highlight_null(color='yellow')"
+ "df2.iloc[0, 2] = np.nan\n",
+ "df2.iloc[4, 3] = np.nan\n",
+ "df2.loc[:4].style.highlight_null(color=\"yellow\")"
]
},
{
@@ -1231,7 +1287,9 @@
"metadata": {},
"outputs": [],
"source": [
- "df2.loc[:4].style.highlight_max(axis=1, props='color:white; font-weight:bold; background-color:darkblue;')"
+ "df2.loc[:4].style.highlight_max(\n",
+ " axis=1, props=(\"color:white; \" \"font-weight:bold; \" \"background-color:darkblue;\")\n",
+ ")"
]
},
{
@@ -1249,7 +1307,9 @@
"outputs": [],
"source": [
"left = pd.Series([1.0, 0.0, 1.0], index=[\"A\", \"B\", \"D\"])\n",
- "df2.loc[:4].style.highlight_between(left=left, right=1.5, axis=1, props='color:white; background-color:purple;')"
+ "df2.loc[:4].style.highlight_between(\n",
+ " left=left, right=1.5, axis=1, props=\"color:white; background-color:purple;\"\n",
+ ")"
]
},
{
@@ -1266,7 +1326,7 @@
"metadata": {},
"outputs": [],
"source": [
- "df2.loc[:4].style.highlight_quantile(q_left=0.85, axis=None, color='yellow')"
+ "df2.loc[:4].style.highlight_quantile(q_left=0.85, axis=None, color=\"yellow\")"
]
},
{
@@ -1290,6 +1350,7 @@
"outputs": [],
"source": [
"import seaborn as sns\n",
+ "\n",
"cm = sns.light_palette(\"green\", as_cmap=True)\n",
"\n",
"df2.style.background_gradient(cmap=cm)"
@@ -1329,9 +1390,9 @@
"metadata": {},
"outputs": [],
"source": [
- "df2.loc[:4].style.set_properties(**{'background-color': 'black',\n",
- " 'color': 'lawngreen',\n",
- " 'border-color': 'white'})"
+ "df2.loc[:4].style.set_properties(\n",
+ " **{\"background-color\": \"black\", \"color\": \"lawngreen\", \"border-color\": \"white\"}\n",
+ ")"
]
},
{
@@ -1354,7 +1415,7 @@
"metadata": {},
"outputs": [],
"source": [
- "df2.style.bar(subset=['A', 'B'], color='#d65f5f')"
+ "df2.style.bar(subset=[\"A\", \"B\"], color=\"#d65f5f\")"
]
},
{
@@ -1372,10 +1433,15 @@
"metadata": {},
"outputs": [],
"source": [
- "df2.style.format('{:.3f}', na_rep=\"\")\\\n",
- " .bar(align=0, vmin=-2.5, vmax=2.5, cmap=\"bwr\", height=50,\n",
- " width=60, props=\"width: 120px; border-right: 1px solid black;\")\\\n",
- " .text_gradient(cmap=\"bwr\", vmin=-2.5, vmax=2.5)"
+ "df2.style.format(\"{:.3f}\", na_rep=\"\").bar(\n",
+ " align=0,\n",
+ " vmin=-2.5,\n",
+ " vmax=2.5,\n",
+ " cmap=\"bwr\",\n",
+ " height=50,\n",
+ " width=60,\n",
+ " props=\"width: 120px; border-right: 1px solid black;\",\n",
+ ").text_gradient(cmap=\"bwr\", vmin=-2.5, vmax=2.5)"
]
},
{
@@ -1398,10 +1464,10 @@
"from IPython.display import HTML\n",
"\n",
"# Test series\n",
- "test1 = pd.Series([-100,-60,-30,-20], name='All Negative')\n",
- "test2 = pd.Series([-10,-5,0,90], name='Both Pos and Neg')\n",
- "test3 = pd.Series([10,20,50,100], name='All Positive')\n",
- "test4 = pd.Series([100, 103, 101, 102], name='Large Positive')\n",
+ "test1 = pd.Series([-100, -60, -30, -20], name=\"All Negative\")\n",
+ "test2 = pd.Series([-10, -5, 0, 90], name=\"Both Pos and Neg\")\n",
+ "test3 = pd.Series([10, 20, 50, 100], name=\"All Positive\")\n",
+ "test4 = pd.Series([100, 103, 101, 102], name=\"Large Positive\")\n",
"\n",
"\n",
"head = \"\"\"\n",
@@ -1417,19 +1483,22 @@
"\n",
"\"\"\"\n",
"\n",
- "aligns = ['left', 'right', 'zero', 'mid', 'mean', 99]\n",
+ "aligns = [\"left\", \"right\", \"zero\", \"mid\", \"mean\", 99]\n",
"for align in aligns:\n",
" row = \"{} | \".format(align)\n",
- " for series in [test1,test2,test3, test4]:\n",
+ " for series in [test1, test2, test3, test4]:\n",
" s = series.copy()\n",
- " s.name=''\n",
- " row += \"{} | \".format(s.to_frame().style.hide(axis='index').bar(align=align, \n",
- " color=['#d65f5f', '#5fba7d'], \n",
- " width=100).to_html()) #testn['width']\n",
- " row += ' '\n",
+ " s.name = \"\"\n",
+ " row += \"{} | \".format(\n",
+ " s.to_frame()\n",
+ " .style.hide(axis=\"index\")\n",
+ " .bar(align=align, color=[\"#d65f5f\", \"#5fba7d\"], width=100)\n",
+ " .to_html()\n",
+ " ) # testn['width']\n",
+ " row += \"\"\n",
" head += row\n",
- " \n",
- "head+= \"\"\"\n",
+ "\n",
+ "head += \"\"\"\n",
"\n",
" \"\"\""
]
@@ -1463,11 +1532,12 @@
"metadata": {},
"outputs": [],
"source": [
- "style1 = df2.style\\\n",
- " .map(style_negative, props='color:red;')\\\n",
- " .map(lambda v: 'opacity: 20%;' if (v < 0.3) and (v > -0.3) else None)\\\n",
- " .set_table_styles([{\"selector\": \"th\", \"props\": \"color: blue;\"}])\\\n",
- " .hide(axis=\"index\")\n",
+ "style1 = (\n",
+ " df2.style.map(style_negative, props=\"color:red;\")\n",
+ " .map(lambda v: \"opacity: 20%;\" if (v < 0.3) and (v > -0.3) else None)\n",
+ " .set_table_styles([{\"selector\": \"th\", \"props\": \"color: blue;\"}])\n",
+ " .hide(axis=\"index\")\n",
+ ")\n",
"style1"
]
},
@@ -1526,11 +1596,14 @@
"outputs": [],
"source": [
"from ipywidgets import widgets\n",
+ "\n",
+ "\n",
"@widgets.interact\n",
- "def f(h_neg=(0, 359, 1), h_pos=(0, 359), s=(0., 99.9), l=(0., 99.9)):\n",
+ "def f(h_neg=(0, 359, 1), h_pos=(0, 359), s=(0.0, 99.9), l_post=(0.0, 99.9)):\n",
" return df2.style.background_gradient(\n",
- " cmap=sns.palettes.diverging_palette(h_neg=h_neg, h_pos=h_pos, s=s, l=l,\n",
- " as_cmap=True)\n",
+ " cmap=sns.palettes.diverging_palette(\n",
+ " h_neg=h_neg, h_pos=h_pos, s=s, l=l_post, as_cmap=True\n",
+ " )\n",
" )"
]
},
@@ -1548,16 +1621,15 @@
"outputs": [],
"source": [
"def magnify():\n",
- " return [dict(selector=\"th\",\n",
- " props=[(\"font-size\", \"4pt\")]),\n",
- " dict(selector=\"td\",\n",
- " props=[('padding', \"0em 0em\")]),\n",
- " dict(selector=\"th:hover\",\n",
- " props=[(\"font-size\", \"12pt\")]),\n",
- " dict(selector=\"tr:hover td:hover\",\n",
- " props=[('max-width', '200px'),\n",
- " ('font-size', '12pt')])\n",
- "]"
+ " return [\n",
+ " {\"selector\": \"th\", \"props\": [(\"font-size\", \"4pt\")]},\n",
+ " {\"selector\": \"td\", \"props\": [(\"padding\", \"0em 0em\")]},\n",
+ " {\"selector\": \"th:hover\", \"props\": [(\"font-size\", \"12pt\")]},\n",
+ " {\n",
+ " \"selector\": \"tr:hover td:hover\",\n",
+ " \"props\": [(\"max-width\", \"200px\"), (\"font-size\", \"12pt\")],\n",
+ " },\n",
+ " ]"
]
},
{
@@ -1566,15 +1638,12 @@
"metadata": {},
"outputs": [],
"source": [
- "np.random.seed(25)\n",
- "cmap = cmap=sns.diverging_palette(5, 250, as_cmap=True)\n",
- "bigdf = pd.DataFrame(np.random.randn(20, 25)).cumsum()\n",
+ "cmap = sns.diverging_palette(5, 250, as_cmap=True)\n",
+ "bigdf = pd.DataFrame(np.random.default_rng(25).standard_normal((20, 25))).cumsum()\n",
"\n",
- "bigdf.style.background_gradient(cmap, axis=1)\\\n",
- " .set_properties(**{'max-width': '80px', 'font-size': '1pt'})\\\n",
- " .set_caption(\"Hover to magnify\")\\\n",
- " .format(precision=2)\\\n",
- " .set_table_styles(magnify())"
+ "bigdf.style.background_gradient(cmap, axis=1).set_properties(\n",
+ " **{\"max-width\": \"80px\", \"font-size\": \"1pt\"}\n",
+ ").set_caption(\"Hover to magnify\").format(precision=2).set_table_styles(magnify())"
]
},
{
@@ -1594,7 +1663,7 @@
"metadata": {},
"outputs": [],
"source": [
- "bigdf = pd.DataFrame(np.random.randn(16, 100))\n",
+ "bigdf = pd.DataFrame(np.random.default_rng().standard_normal((16, 100)))\n",
"bigdf.style.set_sticky(axis=\"index\")"
]
},
@@ -1611,8 +1680,8 @@
"metadata": {},
"outputs": [],
"source": [
- "bigdf.index = pd.MultiIndex.from_product([[\"A\",\"B\"],[0,1],[0,1,2,3]])\n",
- "bigdf.style.set_sticky(axis=\"index\", pixel_size=18, levels=[1,2])"
+ "bigdf.index = pd.MultiIndex.from_product([[\"A\", \"B\"], [0, 1], [0, 1, 2, 3]])\n",
+ "bigdf.style.set_sticky(axis=\"index\", pixel_size=18, levels=[1, 2])"
]
},
{
@@ -1632,7 +1701,7 @@
"metadata": {},
"outputs": [],
"source": [
- "df4 = pd.DataFrame([['', '\"&other\"', '']])\n",
+ "df4 = pd.DataFrame([[\"\", '\"&other\"', \"\"]])\n",
"df4.style"
]
},
@@ -1651,7 +1720,9 @@
"metadata": {},
"outputs": [],
"source": [
- "df4.style.format('{}', escape=\"html\")"
+ "df4.style.format(\n",
+ " '{}', escape=\"html\"\n",
+ ")"
]
},
{
@@ -1693,10 +1764,9 @@
"metadata": {},
"outputs": [],
"source": [
- "df2.style.\\\n",
- " map(style_negative, props='color:red;').\\\n",
- " highlight_max(axis=0).\\\n",
- " to_excel('styled.xlsx', engine='openpyxl')"
+ "df2.style.map(style_negative, props=\"color:red;\").highlight_max(axis=0).to_excel(\n",
+ " \"styled.xlsx\", engine=\"openpyxl\"\n",
+ ")"
]
},
{
@@ -1765,7 +1835,11 @@
"metadata": {},
"outputs": [],
"source": [
- "print(pd.DataFrame([[1,2],[3,4]], index=['i1', 'i2'], columns=['c1', 'c2']).style.to_html())"
+ "print(\n",
+ " pd.DataFrame(\n",
+ " [[1, 2], [3, 4]], index=[\"i1\", \"i2\"], columns=[\"c1\", \"c2\"]\n",
+ " ).style.to_html()\n",
+ ")"
]
},
{
@@ -1783,9 +1857,8 @@
"metadata": {},
"outputs": [],
"source": [
- "df4 = pd.DataFrame([['text']])\n",
- "df4.style.map(lambda x: 'color:green;')\\\n",
- " .map(lambda x: 'color:red;')"
+ "df4 = pd.DataFrame([[\"text\"]])\n",
+ "df4.style.map(lambda x: \"color:green;\").map(lambda x: \"color:red;\")"
]
},
{
@@ -1794,8 +1867,7 @@
"metadata": {},
"outputs": [],
"source": [
- "df4.style.map(lambda x: 'color:red;')\\\n",
- " .map(lambda x: 'color:green;')"
+ "df4.style.map(lambda x: \"color:red;\").map(lambda x: \"color:green;\")"
]
},
{
@@ -1820,9 +1892,9 @@
"metadata": {},
"outputs": [],
"source": [
- "df4.style.set_uuid('a_')\\\n",
- " .set_table_styles([{'selector': 'td', 'props': 'color:red;'}])\\\n",
- " .map(lambda x: 'color:green;')"
+ "df4.style.set_uuid(\"a_\").set_table_styles(\n",
+ " [{\"selector\": \"td\", \"props\": \"color:red;\"}]\n",
+ ").map(lambda x: \"color:green;\")"
]
},
{
@@ -1838,11 +1910,12 @@
"metadata": {},
"outputs": [],
"source": [
- "df4.style.set_uuid('b_')\\\n",
- " .set_table_styles([{'selector': 'td', 'props': 'color:red;'},\n",
- " {'selector': '.cls-1', 'props': 'color:blue;'}])\\\n",
- " .map(lambda x: 'color:green;')\\\n",
- " .set_td_classes(pd.DataFrame([['cls-1']]))"
+ "df4.style.set_uuid(\"b_\").set_table_styles(\n",
+ " [\n",
+ " {\"selector\": \"td\", \"props\": \"color:red;\"},\n",
+ " {\"selector\": \".cls-1\", \"props\": \"color:blue;\"},\n",
+ " ]\n",
+ ").map(lambda x: \"color:green;\").set_td_classes(pd.DataFrame([[\"cls-1\"]]))"
]
},
{
@@ -1858,12 +1931,13 @@
"metadata": {},
"outputs": [],
"source": [
- "df4.style.set_uuid('c_')\\\n",
- " .set_table_styles([{'selector': 'td', 'props': 'color:red;'},\n",
- " {'selector': '.cls-1', 'props': 'color:blue;'},\n",
- " {'selector': 'td.data', 'props': 'color:yellow;'}])\\\n",
- " .map(lambda x: 'color:green;')\\\n",
- " .set_td_classes(pd.DataFrame([['cls-1']]))"
+ "df4.style.set_uuid(\"c_\").set_table_styles(\n",
+ " [\n",
+ " {\"selector\": \"td\", \"props\": \"color:red;\"},\n",
+ " {\"selector\": \".cls-1\", \"props\": \"color:blue;\"},\n",
+ " {\"selector\": \"td.data\", \"props\": \"color:yellow;\"},\n",
+ " ]\n",
+ ").map(lambda x: \"color:green;\").set_td_classes(pd.DataFrame([[\"cls-1\"]]))"
]
},
{
@@ -1881,12 +1955,13 @@
"metadata": {},
"outputs": [],
"source": [
- "df4.style.set_uuid('d_')\\\n",
- " .set_table_styles([{'selector': 'td', 'props': 'color:red;'},\n",
- " {'selector': '.cls-1', 'props': 'color:blue;'},\n",
- " {'selector': 'td.data', 'props': 'color:yellow;'}])\\\n",
- " .map(lambda x: 'color:green !important;')\\\n",
- " .set_td_classes(pd.DataFrame([['cls-1']]))"
+ "df4.style.set_uuid(\"d_\").set_table_styles(\n",
+ " [\n",
+ " {\"selector\": \"td\", \"props\": \"color:red;\"},\n",
+ " {\"selector\": \".cls-1\", \"props\": \"color:blue;\"},\n",
+ " {\"selector\": \"td.data\", \"props\": \"color:yellow;\"},\n",
+ " ]\n",
+ ").map(lambda x: \"color:green !important;\").set_td_classes(pd.DataFrame([[\"cls-1\"]]))"
]
},
{
@@ -1940,8 +2015,8 @@
"metadata": {},
"outputs": [],
"source": [
- "with open(\"templates/myhtml.tpl\") as f:\n",
- " print(f.read())"
+ "with open(\"templates/myhtml.tpl\") as f_html:\n",
+ " print(f_html.read())"
]
},
{
@@ -1960,10 +2035,12 @@
"source": [
"class MyStyler(Styler):\n",
" env = Environment(\n",
- " loader=ChoiceLoader([\n",
- " FileSystemLoader(\"templates\"), # contains ours\n",
- " Styler.loader, # the default\n",
- " ])\n",
+ " loader=ChoiceLoader(\n",
+ " [\n",
+ " FileSystemLoader(\"templates\"), # contains ours\n",
+ " Styler.loader, # the default\n",
+ " ]\n",
+ " )\n",
" )\n",
" template_html_table = env.get_template(\"myhtml.tpl\")"
]
@@ -2045,8 +2122,8 @@
},
"outputs": [],
"source": [
- "with open(\"templates/html_style_structure.html\") as f:\n",
- " style_structure = f.read()"
+ "with open(\"templates/html_style_structure.html\") as f_sty:\n",
+ " style_structure = f_sty.read()"
]
},
{
@@ -2073,8 +2150,8 @@
},
"outputs": [],
"source": [
- "with open(\"templates/html_table_structure.html\") as f:\n",
- " table_structure = f.read()"
+ "with open(\"templates/html_table_structure.html\") as f_table_struct:\n",
+ " table_structure = f_table_struct.read()"
]
},
{
@@ -2106,7 +2183,7 @@
"# from IPython.display import HTML\n",
"# with open(\"themes/nature_with_gtoc/static/nature.css_t\") as f:\n",
"# css = f.read()\n",
- " \n",
+ "\n",
"# HTML(''.format(css))"
]
}
diff --git a/pandas/core/arrays/string_.py b/pandas/core/arrays/string_.py
index b3aa782341c77..e4daf9ed450fb 100644
--- a/pandas/core/arrays/string_.py
+++ b/pandas/core/arrays/string_.py
@@ -190,7 +190,7 @@ def __eq__(self, other: object) -> bool:
# cannot be checked with normal `==`
if isinstance(other, str):
# TODO should dtype == "string" work for the NaN variant?
- if other == "string" or other == self.name: # noqa: PLR1714
+ if other == "string" or other == self.name:
return True
try:
other = self.construct_from_string(other)
diff --git a/pandas/tests/indexes/test_old_base.py b/pandas/tests/indexes/test_old_base.py
index cd3d599abd30e..0199e21bfc980 100644
--- a/pandas/tests/indexes/test_old_base.py
+++ b/pandas/tests/indexes/test_old_base.py
@@ -455,7 +455,7 @@ def test_insert_out_of_bounds(self, index, using_infer_string):
msg = "slice indices must be integers or None or have an __index__ method"
if using_infer_string and (
- index.dtype == "string" or index.dtype == "category" # noqa: PLR1714
+ index.dtype == "string" or index.dtype == "category"
):
msg = "loc must be an integer between"
diff --git a/pyproject.toml b/pyproject.toml
index d0fcdc4b21b33..1386546996bf2 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -324,7 +324,8 @@ ignore = [
"PT019",
# The following rules may cause conflicts when used with the formatter:
"ISC001",
-
+ # if-stmt-min-max
+ "PLR1730",
### TODO: Enable gradually
# Useless statement
@@ -341,8 +342,10 @@ ignore = [
"RUF012",
# type-comparison
"E721",
-
- # Additional pylint rules
+ # repeated-equality-comparison
+ "PLR1714",
+ # self-or-cls-assignment
+ "PLW0642",
# literal-membership
"PLR6201", # 847 errors
# Method could be a function, class method, or static method
|