diff --git a/ci/code_checks.sh b/ci/code_checks.sh
index 21104c2e00450..d0afdb4df596f 100755
--- a/ci/code_checks.sh
+++ b/ci/code_checks.sh
@@ -100,7 +100,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
-i "pandas.Series.sparse.fill_value SA01" \
-i "pandas.Series.sparse.from_coo PR07,SA01" \
-i "pandas.Series.sparse.npoints SA01" \
- -i "pandas.Series.sparse.sp_values SA01" \
-i "pandas.Timedelta.max PR02" \
-i "pandas.Timedelta.min PR02" \
-i "pandas.Timedelta.resolution PR02" \
diff --git a/doc/source/user_guide/style.ipynb b/doc/source/user_guide/style.ipynb
index daecfce6ecebc..1afc5d0cf3b3c 100644
--- a/doc/source/user_guide/style.ipynb
+++ b/doc/source/user_guide/style.ipynb
@@ -46,7 +46,6 @@
},
"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"
]
@@ -78,7 +77,6 @@
"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",
@@ -104,11 +102,11 @@
"metadata": {},
"outputs": [],
"source": [
- "weather_df = pd.DataFrame(np.random.rand(10,2)*5, \n",
+ "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",
"\n",
- "def rain_condition(v): \n",
+ "def rain_condition(v):\n",
" if v < 1.75:\n",
" return \"Dry\"\n",
" elif v < 2.75:\n",
@@ -227,9 +225,9 @@
"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",
+ "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",
"df.style"
]
},
@@ -243,62 +241,62 @@
"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",
+ " .hide([(\"Random\", \"Tumour\"), (\"Random\", \"Non-Tumour\")], axis=\"columns\")\\\n",
+ " .format(\"{:.0f}\")\\\n",
" .set_table_styles([{\n",
- " 'selector': '',\n",
- " 'props': 'border-collapse: separate;'\n",
+ " \"selector\": \"\",\n",
+ " \"props\": \"border-collapse: separate;\"\n",
" },{\n",
- " 'selector': 'caption',\n",
- " 'props': 'caption-side: bottom; font-size:1.3em;'\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",
+ " \"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",
+ " \"selector\": \"th:not(.index_name)\",\n",
+ " \"props\": \"background-color: #000066; color: white;\"\n",
" },{\n",
- " 'selector': 'th.col_heading',\n",
- " 'props': 'text-align: center;'\n",
+ " \"selector\": \"th.col_heading\",\n",
+ " \"props\": \"text-align: center;\"\n",
" },{\n",
- " 'selector': 'th.col_heading.level0',\n",
- " 'props': 'font-size: 1.5em;'\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",
+ " \"selector\": \"th.col2\",\n",
+ " \"props\": \"border-left: 1px solid white;\"\n",
" },{\n",
- " 'selector': '.col2',\n",
- " 'props': 'border-left: 1px solid #000066;'\n",
+ " \"selector\": \".col2\",\n",
+ " \"props\": \"border-left: 1px solid #000066;\"\n",
" },{\n",
- " 'selector': 'td',\n",
- " 'props': 'text-align: center; font-weight:bold;'\n",
+ " \"selector\": \"td\",\n",
+ " \"props\": \"text-align: center; font-weight:bold;\"\n",
" },{\n",
- " 'selector': '.true',\n",
- " 'props': 'background-color: #e6ffe6;'\n",
+ " \"selector\": \".true\",\n",
+ " \"props\": \"background-color: #e6ffe6;\"\n",
" },{\n",
- " 'selector': '.false',\n",
- " 'props': 'background-color: #ffe6e6;'\n",
+ " \"selector\": \".false\",\n",
+ " \"props\": \"background-color: #ffe6e6;\"\n",
" },{\n",
- " 'selector': '.border-red',\n",
- " 'props': 'border: 2px dashed red;'\n",
+ " \"selector\": \".border-red\",\n",
+ " \"props\": \"border: 2px dashed red;\"\n",
" },{\n",
- " 'selector': '.border-green',\n",
- " 'props': 'border: 2px dashed green;'\n",
+ " \"selector\": \".border-green\",\n",
+ " \"props\": \"border: 2px dashed green;\"\n",
" },{\n",
- " 'selector': 'td:hover',\n",
- " 'props': 'background-color: #ffffb3;'\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",
+ " .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",
+ " .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"
+ " 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"
]
},
{
@@ -325,7 +323,7 @@
"metadata": {},
"outputs": [],
"source": [
- "s = df.style.format('{:.0f}').hide([('Random', 'Tumour'), ('Random', 'Non-Tumour')], axis=\"columns\")\n",
+ "s = df.style.format(\"{:.0f}\").hide([(\"Random\", \"Tumour\"), (\"Random\", \"Non-Tumour\")], axis=\"columns\")\n",
"s"
]
},
@@ -337,8 +335,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 +393,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 +415,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\")"
]
},
{
@@ -435,9 +433,9 @@
"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",
+ " {\"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)"
]
},
@@ -449,8 +447,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\")"
]
},
{
@@ -469,8 +467,8 @@
"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",
+ " (\"Regression\", \"Tumour\"): [{\"selector\": \"th\", \"props\": \"border-left: 1px solid white\"},\n",
+ " {\"selector\": \"td\", \"props\": \"border-left: 1px solid #000066\"}]\n",
"}, overwrite=False, axis=0)"
]
},
@@ -482,8 +480,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 +506,7 @@
"outputs": [],
"source": [
"out = s.set_table_attributes('class=\"my-table-cls\"').to_html()\n",
- "print(out[out.find(' -0.3) else None)\n",
+ "s2 = 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",
"s2"
]
},
@@ -612,8 +610,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 +627,9 @@
"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",
+ "s2.apply(highlight_max, props=\"color:white;background-color:darkblue\", axis=0)"
]
},
{
@@ -642,8 +640,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 +657,8 @@
"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)\\\n",
+ " .apply(highlight_max, props=\"color:white;background-color:purple\", axis=None)"
]
},
{
@@ -671,8 +669,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\")"
]
},
{
@@ -736,8 +734,8 @@
"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",
+ " \"selector\": \"caption\",\n",
+ " \"props\": \"caption-side: bottom; font-size:1.25em;\"\n",
" }], overwrite=False)"
]
},
@@ -749,8 +747,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 +766,12 @@
"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([[\"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;\")"
]
},
{
@@ -784,8 +782,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\")"
]
},
{
@@ -802,12 +800,12 @@
"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",
+ " {\"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",
+ "cell_border = pd.DataFrame([[\"border-green \", \" \", \" \", \"border-red \"],\n",
+ " [\" \", \" \", \" \", \" \"]],\n",
+ " index=df.index,\n",
" columns=df.columns[:4])\n",
"s.set_td_classes(cell_color + cell_border)"
]
@@ -820,8 +818,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 +845,9 @@
"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(np.random.randn(4,4),\n",
+ " pd.MultiIndex.from_product([[\"A\", \"B\"], [\"r1\", \"r2\"]]),\n",
+ " columns=[\"c1\",\"c2\",\"c3\",\"c4\"])\n",
"df3"
]
},
@@ -866,9 +864,9 @@
"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(highlight_max, props=\"color:red;\", axis=0, subset=slice_)\\\n",
+ " .set_properties(**{\"background-color\": \"#ffffb3\"}, subset=slice_)"
]
},
{
@@ -885,9 +883,9 @@
"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(highlight_max, props=\"color:red;\", axis=0, subset=slice_)\\\n",
+ " .set_properties(**{\"background-color\": \"#ffffb3\"}, subset=slice_)"
]
},
{
@@ -903,9 +901,9 @@
"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(highlight_max, props=\"color:red;\", axis=1, subset=slice_)\\\n",
+ " .set_properties(**{\"background-color\": \"#ffffb3\"}, subset=slice_)"
]
},
{
@@ -923,9 +921,9 @@
"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(highlight_max, props=\"color:red;\", axis=1, subset=slice_)\\\n",
+ " .set_properties(**{\"background-color\": \"#ffffb3\"}, subset=slice_)"
]
},
{
@@ -1053,7 +1051,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 +1080,9 @@
"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(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)"
]
},
{
@@ -1105,13 +1103,13 @@
"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",
+ "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",
+ " {\"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)"
]
},
@@ -1152,9 +1150,9 @@
" \"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",
+ "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",
"print(html.to_html())"
]
@@ -1215,7 +1213,7 @@
"source": [
"df2.iloc[0,2] = np.nan\n",
"df2.iloc[4,3] = np.nan\n",
- "df2.loc[:4].style.highlight_null(color='yellow')"
+ "df2.loc[:4].style.highlight_null(color=\"yellow\")"
]
},
{
@@ -1231,7 +1229,7 @@
"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(axis=1, props=\"color:white; font-weight:bold; background-color:darkblue;\")"
]
},
{
@@ -1249,7 +1247,7 @@
"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(left=left, right=1.5, axis=1, props=\"color:white; background-color:purple;\")"
]
},
{
@@ -1266,7 +1264,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\")"
]
},
{
@@ -1329,9 +1327,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(**{\"background-color\": \"black\",\n",
+ " \"color\": \"lawngreen\",\n",
+ " \"border-color\": \"white\"})"
]
},
{
@@ -1354,7 +1352,7 @@
"metadata": {},
"outputs": [],
"source": [
- "df2.style.bar(subset=['A', 'B'], color='#d65f5f')"
+ "df2.style.bar(subset=[\"A\", \"B\"], color=\"#d65f5f\")"
]
},
{
@@ -1372,7 +1370,7 @@
"metadata": {},
"outputs": [],
"source": [
- "df2.style.format('{:.3f}', na_rep=\"\")\\\n",
+ "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)"
@@ -1398,10 +1396,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,18 +1415,18 @@
"\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",
" s = series.copy()\n",
- " s.name=''\n",
- " row += \"{} | \".format(s.to_frame().style.hide(axis='index').bar(align=align, \n",
- " color=['#d65f5f', '#5fba7d'], \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",
+ " row += \"\"\n",
" head += row\n",
- " \n",
+ "\n",
"head+= \"\"\"\n",
"\n",
" \"\"\""
@@ -1464,8 +1462,8 @@
"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",
+ " .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"
@@ -1548,15 +1546,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 [{\"selector\": \"th\",\n",
+ " \"props\": [(\"font-size\", \"4pt\")]},\n",
+ " {\"selector\": \"td\",\n",
+ " \"props\": [(\"padding\", \"0em 0em\")]},\n",
+ " {\"selector\": \"th:hover\",\n",
+ " \"props\": [(\"font-size\", \"12pt\")]},\n",
+ " {\"selector\": \"tr:hover td:hover\",\n",
+ " \"props\": [(\"max-width\", \"200px\"),\n",
+ " (\"font-size\", \"12pt\")]}\n",
"]"
]
},
@@ -1571,7 +1569,7 @@
"bigdf = pd.DataFrame(np.random.randn(20, 25)).cumsum()\n",
"\n",
"bigdf.style.background_gradient(cmap, axis=1)\\\n",
- " .set_properties(**{'max-width': '80px', 'font-size': '1pt'})\\\n",
+ " .set_properties(**{\"max-width\": \"80px\", \"font-size\": \"1pt\"})\\\n",
" .set_caption(\"Hover to magnify\")\\\n",
" .format(precision=2)\\\n",
" .set_table_styles(magnify())"
@@ -1632,7 +1630,7 @@
"metadata": {},
"outputs": [],
"source": [
- "df4 = pd.DataFrame([['', '\"&other\"', '']])\n",
+ "df4 = pd.DataFrame([[\"\", '\"&other\"', \"\"]])\n",
"df4.style"
]
},
@@ -1694,9 +1692,9 @@
"outputs": [],
"source": [
"df2.style.\\\n",
- " map(style_negative, props='color:red;').\\\n",
+ " map(style_negative, props=\"color:red;\").\\\n",
" highlight_max(axis=0).\\\n",
- " to_excel('styled.xlsx', engine='openpyxl')"
+ " to_excel(\"styled.xlsx\", engine=\"openpyxl\")"
]
},
{
@@ -1765,7 +1763,7 @@
"metadata": {},
"outputs": [],
"source": [
- "print(pd.DataFrame([[1,2],[3,4]], index=['i1', 'i2'], columns=['c1', 'c2']).style.to_html())"
+ "print(pd.DataFrame([[1,2],[3,4]], index=[\"i1\", \"i2\"], columns=[\"c1\", \"c2\"]).style.to_html())"
]
},
{
@@ -1783,9 +1781,9 @@
"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;\")\\\n",
+ " .map(lambda x: \"color:red;\")"
]
},
{
@@ -1794,8 +1792,8 @@
"metadata": {},
"outputs": [],
"source": [
- "df4.style.map(lambda x: 'color:red;')\\\n",
- " .map(lambda x: 'color:green;')"
+ "df4.style.map(lambda x: \"color:red;\")\\\n",
+ " .map(lambda x: \"color:green;\")"
]
},
{
@@ -1820,9 +1818,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_\")\\\n",
+ " .set_table_styles([{\"selector\": \"td\", \"props\": \"color:red;\"}])\\\n",
+ " .map(lambda x: \"color:green;\")"
]
},
{
@@ -1838,11 +1836,11 @@
"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_\")\\\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\"]]))"
]
},
{
@@ -1858,12 +1856,12 @@
"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_\")\\\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\"]]))"
]
},
{
@@ -1881,12 +1879,12 @@
"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_\")\\\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\"]]))"
]
},
{
@@ -2106,7 +2104,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/_numba/kernels/min_max_.py b/pandas/core/_numba/kernels/min_max_.py
index 59d36732ebae6..6e57e62c13a6e 100644
--- a/pandas/core/_numba/kernels/min_max_.py
+++ b/pandas/core/_numba/kernels/min_max_.py
@@ -112,11 +112,9 @@ def grouped_min_max(
continue
if is_max:
- if val > output[lab]:
- output[lab] = val
+ output[lab] = max(val, output[lab])
else:
- if val < output[lab]:
- output[lab] = val
+ output[lab] = min(val, output[lab])
# Set labels that don't satisfy min_periods as np.nan
for lab, count in enumerate(nobs):
diff --git a/pandas/core/arrays/sparse/array.py b/pandas/core/arrays/sparse/array.py
index a09dc20af3b36..f3eaca364a240 100644
--- a/pandas/core/arrays/sparse/array.py
+++ b/pandas/core/arrays/sparse/array.py
@@ -601,7 +601,22 @@ def sp_index(self) -> SparseIndex:
@property
def sp_values(self) -> np.ndarray:
"""
- An ndarray containing the non- ``fill_value`` values.
+ An ndarray containing the non-``fill_value`` values.
+
+ This method retrieves the non-fill values from a SparseArray. SparseArrays
+ are designed to efficiently store large arrays of data where most of the
+ elements are the same (the fill value). This method allows you to access
+ the actual data points that differ from the fill value.
+
+ Returns
+ -------
+ ndarray
+ An array containing the non-fill values.
+
+ See Also
+ --------
+ Series.sparse.fill_value : The fill value for the SparseArray.
+ arrays.SparseArray : Represents an array with sparse data.
Examples
--------
@@ -610,6 +625,7 @@ def sp_values(self) -> np.ndarray:
>>> s.sp_values
array([1, 2])
"""
+
return self._sparse_values
@property
diff --git a/pandas/core/dtypes/astype.py b/pandas/core/dtypes/astype.py
index 086f7d2da6640..6555fb09adc73 100644
--- a/pandas/core/dtypes/astype.py
+++ b/pandas/core/dtypes/astype.py
@@ -125,7 +125,7 @@ def _astype_nansafe(
)
raise ValueError(msg)
- if copy or arr.dtype == object or dtype == object:
+ if copy or object in (arr.dtype, dtype):
# Explicit copy, or required since NumPy can't view from / to object.
return arr.astype(dtype, copy=True)
diff --git a/pandas/core/dtypes/cast.py b/pandas/core/dtypes/cast.py
index 6ba07b1761557..9b780e512a11d 100644
--- a/pandas/core/dtypes/cast.py
+++ b/pandas/core/dtypes/cast.py
@@ -683,9 +683,7 @@ def _maybe_promote(dtype: np.dtype, fill_value=np.nan):
elif dtype.kind == "f":
mst = np.min_scalar_type(fill_value)
- if mst > dtype:
- # e.g. mst is np.float64 and dtype is np.float32
- dtype = mst
+ dtype = max(mst, dtype)
elif dtype.kind == "c":
mst = np.min_scalar_type(fill_value)
@@ -718,9 +716,7 @@ def _maybe_promote(dtype: np.dtype, fill_value=np.nan):
elif dtype.kind == "c":
mst = np.min_scalar_type(fill_value)
- if mst > dtype:
- # e.g. mst is np.complex128 and dtype is np.complex64
- dtype = mst
+ dtype = max(mst, dtype)
else:
dtype = np.dtype(np.object_)
diff --git a/pandas/core/nanops.py b/pandas/core/nanops.py
index e775156a6ae2f..040dd950b58be 100644
--- a/pandas/core/nanops.py
+++ b/pandas/core/nanops.py
@@ -460,11 +460,8 @@ def newfunc(values: np.ndarray, *, axis: AxisInt | None = None, **kwargs):
axis == 1
and values.ndim == 2
and values.flags["C_CONTIGUOUS"]
- # only takes this path for wide arrays (long dataframes), for threshold see
- # https://github.com/pandas-dev/pandas/pull/43311#issuecomment-974891737
- and (values.shape[1] / 1000) > values.shape[0]
- and values.dtype != object
- and values.dtype != bool
+ and values.shape[1] / 1000 > values.shape[0]
+ and values.dtype not in (object, bool)
):
arrs = list(values)
if kwargs.get("mask") is not None:
diff --git a/pandas/core/strings/accessor.py b/pandas/core/strings/accessor.py
index 6d10365a1b968..6a23b4e2d7a4f 100644
--- a/pandas/core/strings/accessor.py
+++ b/pandas/core/strings/accessor.py
@@ -1366,6 +1366,10 @@ def match(self, pat: str, case: bool = True, flags: int = 0, na=None):
"""
Determine if each string starts with a match of a regular expression.
+ This method checks if each string in the Series starts with a substring
+ that matches the given regular expression pattern. It returns a boolean
+ Series indicating whether each string meets the condition.
+
Parameters
----------
pat : str
@@ -1402,6 +1406,7 @@ def match(self, pat: str, case: bool = True, flags: int = 0, na=None):
2 False
dtype: bool
"""
+
result = self._data.array._str_match(pat, case=case, flags=flags, na=na)
return self._wrap_result(result, fill_value=na, returns_string=False)
diff --git a/pandas/io/excel/_odfreader.py b/pandas/io/excel/_odfreader.py
index f79417d11080d..62002e4844b32 100644
--- a/pandas/io/excel/_odfreader.py
+++ b/pandas/io/excel/_odfreader.py
@@ -142,8 +142,7 @@ def get_sheet_data(
empty_cells = 0
table_row.extend([value] * column_repeat)
- if max_row_len < len(table_row):
- max_row_len = len(table_row)
+ max_row_len = max(max_row_len, len(table_row))
row_repeat = self._get_row_repeat(sheet_row)
if len(table_row) == 0:
diff --git a/pandas/tests/arithmetic/test_numeric.py b/pandas/tests/arithmetic/test_numeric.py
index d205569270705..d48a2d3c9c027 100644
--- a/pandas/tests/arithmetic/test_numeric.py
+++ b/pandas/tests/arithmetic/test_numeric.py
@@ -274,9 +274,7 @@ def test_numeric_arr_rdiv_tdscalar(self, three_days, numeric_idx, box_with_array
expected = TimedeltaIndex(["3 Days", "36 Hours"])
if isinstance(three_days, np.timedelta64):
dtype = three_days.dtype
- if dtype < np.dtype("m8[s]"):
- # i.e. resolution is lower -> use lowest supported resolution
- dtype = np.dtype("m8[s]")
+ dtype = max(dtype, np.dtype("m8[s]"))
expected = expected.astype(dtype)
elif type(three_days) is timedelta:
expected = expected.astype("m8[us]")
diff --git a/pandas/tests/frame/test_query_eval.py b/pandas/tests/frame/test_query_eval.py
index a574989860957..bbc3caae9fccb 100644
--- a/pandas/tests/frame/test_query_eval.py
+++ b/pandas/tests/frame/test_query_eval.py
@@ -1388,7 +1388,7 @@ def test_expr_with_column_name_with_backtick_and_hash(self):
def test_expr_with_column_name_with_backtick(self):
# GH 59285
df = DataFrame({"a`b": (1, 2, 3), "ab": (4, 5, 6)})
- result = df.query("`a``b` < 2") # noqa
+ result = df.query("`a``b` < 2")
# Note: Formatting checks may wrongly consider the above ``inline code``.
expected = df[df["a`b"] < 2]
tm.assert_frame_equal(result, expected)
|