From 5169f5c218ad7885dcbc740df7667d424b82beca Mon Sep 17 00:00:00 2001 From: Brian Date: Sun, 17 Jan 2021 16:26:07 -0500 Subject: [PATCH 1/9] Includes the reading from Excel example as suggested via #38990 --- .../comparison_with_spreadsheets.rst | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/doc/source/getting_started/comparison/comparison_with_spreadsheets.rst b/doc/source/getting_started/comparison/comparison_with_spreadsheets.rst index 13029173b2e65..aecd90a071129 100644 --- a/doc/source/getting_started/comparison/comparison_with_spreadsheets.rst +++ b/doc/source/getting_started/comparison/comparison_with_spreadsheets.rst @@ -89,13 +89,6 @@ Both `Excel ` can import data from various sources in various formats. -Excel files -''''''''''' - -Excel opens `various Excel file formats `_ -by double-clicking them, or using `the Open menu `_. -In pandas, you use :ref:`special methods for reading and writing from/to Excel files `. - CSV ''' @@ -125,6 +118,27 @@ would be: # alternatively, read_table is an alias to read_csv with tab delimiter tips = pd.read_table("tips.csv", header=None) +Excel files +''''''''''' + +Excel opens `various Excel file formats `_ +by double-clicking them, or using `the Open menu `_. +In pandas, you use :ref:`special methods for reading and writing from/to Excel files `. + +Let's first :ref:`create a new Excel file ` based on the ``tips`` dataframe in the above example: + +.. code-block:: python + + tips.to_excel("./tips.xlsx") + +Should you wish to subsequently access the data in the ``tips.xlsx`` file, you can read it into your module using + +.. code-block:: python + + tips_df = read_excel("./tips.xlsx", header=None) + +You have just read in an Excel file using pandas! + Limiting output ~~~~~~~~~~~~~~~ From 7037920d1307fa77fe48836260627f15a3124f90 Mon Sep 17 00:00:00 2001 From: Brian Date: Sun, 17 Jan 2021 17:01:07 -0500 Subject: [PATCH 2/9] Updated Comparison to Excel documentation with examples of reading Excel file, and fixed typo via #38990 --- .../getting_started/comparison/comparison_with_spreadsheets.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/getting_started/comparison/comparison_with_spreadsheets.rst b/doc/source/getting_started/comparison/comparison_with_spreadsheets.rst index aecd90a071129..7f864ce80fe4e 100644 --- a/doc/source/getting_started/comparison/comparison_with_spreadsheets.rst +++ b/doc/source/getting_started/comparison/comparison_with_spreadsheets.rst @@ -135,7 +135,7 @@ Should you wish to subsequently access the data in the ``tips.xlsx`` file, you c .. code-block:: python - tips_df = read_excel("./tips.xlsx", header=None) + tips_df = pd.read_excel("./tips.xlsx", header=None) You have just read in an Excel file using pandas! From d8df1fc6d5d0b773e4687b04b1543b3c01df40b5 Mon Sep 17 00:00:00 2001 From: Jeff Reback Date: Thu, 21 Jan 2021 12:37:50 -0500 Subject: [PATCH 3/9] Update doc/source/getting_started/comparison/comparison_with_spreadsheets.rst Co-authored-by: Aidan Feldman --- .../getting_started/comparison/comparison_with_spreadsheets.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/getting_started/comparison/comparison_with_spreadsheets.rst b/doc/source/getting_started/comparison/comparison_with_spreadsheets.rst index 7f864ce80fe4e..55f999c099e23 100644 --- a/doc/source/getting_started/comparison/comparison_with_spreadsheets.rst +++ b/doc/source/getting_started/comparison/comparison_with_spreadsheets.rst @@ -135,7 +135,7 @@ Should you wish to subsequently access the data in the ``tips.xlsx`` file, you c .. code-block:: python - tips_df = pd.read_excel("./tips.xlsx", header=None) + tips_df = pd.read_excel("./tips.xlsx", index_col=0) You have just read in an Excel file using pandas! From 46d8994fcb936369a14c732a5f4cefa1df743566 Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 26 Mar 2021 22:40:10 -0400 Subject: [PATCH 4/9] clear method updated to clear _todo, hidden index and columns --- pandas/io/formats/style.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pandas/io/formats/style.py b/pandas/io/formats/style.py index 5ec2141028fa4..cda0893b7c1ff 100644 --- a/pandas/io/formats/style.py +++ b/pandas/io/formats/style.py @@ -202,7 +202,6 @@ def __init__( ] = defaultdict(lambda: partial(_default_formatter, precision=def_precision)) self.precision = precision # can be removed on set_precision depr cycle self.na_rep = na_rep # can be removed on set_na_rep depr cycle - self.format(formatter=None, precision=precision, na_rep=na_rep) def _repr_html_(self) -> str: """ @@ -860,7 +859,13 @@ def clear(self) -> None: self.ctx.clear() self.tooltips = None self.cell_context = {} - self._todo = [] + + self._todo.clear() + self.hidden_index = False + self.hidden_columns = [] + self.tooltips = None + # self.format and self.table_styles may be dependent on user + # input in self.__init__() def _compute(self): """ From 35fbd61f0a0d3bd061712cf5d1f5afbdf4cd0642 Mon Sep 17 00:00:00 2001 From: Brian Date: Sat, 27 Mar 2021 13:51:12 -0400 Subject: [PATCH 5/9] BUG: tests written for updated styler.clear method for #40484 --- .gitignore | 1 + pandas/io/formats/style.py | 2 +- pandas/tests/io/formats/style/test_style.py | 5 +++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index b682d93efbd04..dbd3c60cec76c 100644 --- a/.gitignore +++ b/.gitignore @@ -119,3 +119,4 @@ doc/build/html/index.html doc/tmp.sv env/ doc/source/savefig/ +virtualenvs/ diff --git a/pandas/io/formats/style.py b/pandas/io/formats/style.py index cda0893b7c1ff..099f4ec8a4951 100644 --- a/pandas/io/formats/style.py +++ b/pandas/io/formats/style.py @@ -859,8 +859,8 @@ def clear(self) -> None: self.ctx.clear() self.tooltips = None self.cell_context = {} - self._todo.clear() + self.hidden_index = False self.hidden_columns = [] self.tooltips = None diff --git a/pandas/tests/io/formats/style/test_style.py b/pandas/tests/io/formats/style/test_style.py index 977b92e217868..f6680f3c220d4 100644 --- a/pandas/tests/io/formats/style/test_style.py +++ b/pandas/tests/io/formats/style/test_style.py @@ -173,10 +173,13 @@ def test_clear(self): tt = DataFrame({"A": [None, "tt"]}) css = DataFrame({"A": [None, "cls-a"]}) s = self.df.style.highlight_max().set_tooltips(tt).set_td_classes(css) + s = s.hide_index().hide_columns("A") # _todo, tooltips and cell_context items added to.. assert len(s._todo) > 0 assert s.tooltips assert len(s.cell_context) > 0 + assert s.hidden_index is True + assert len(s.hidden_columns) > 0 s = s._compute() # ctx item affected when a render takes place. _todo is maintained @@ -189,6 +192,8 @@ def test_clear(self): assert len(s._todo) == 0 assert not s.tooltips assert len(s.cell_context) == 0 + assert s.hidden_index is False + assert len(s.hidden_columns) == 0 def test_render(self): df = DataFrame({"A": [0, 1]}) From 6d9f40613160b0241736b06b2dee8d0388b26e50 Mon Sep 17 00:00:00 2001 From: Brian Date: Sat, 27 Mar 2021 13:57:41 -0400 Subject: [PATCH 6/9] minor fix to a missing line in style.py related to #40484 --- pandas/io/formats/style.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/io/formats/style.py b/pandas/io/formats/style.py index 099f4ec8a4951..a67001cf1e865 100644 --- a/pandas/io/formats/style.py +++ b/pandas/io/formats/style.py @@ -202,6 +202,7 @@ def __init__( ] = defaultdict(lambda: partial(_default_formatter, precision=def_precision)) self.precision = precision # can be removed on set_precision depr cycle self.na_rep = na_rep # can be removed on set_na_rep depr cycle + self.format(formatter=None, precision=precision, na_rep=na_rep) def _repr_html_(self) -> str: """ From 28c3d0f0576005f0cd40ae6a75b6d971842fac72 Mon Sep 17 00:00:00 2001 From: Brian Date: Sat, 27 Mar 2021 16:03:49 -0400 Subject: [PATCH 7/9] What's new documentation updated for #40484 --- doc/source/whatsnew/v1.3.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v1.3.0.rst b/doc/source/whatsnew/v1.3.0.rst index 9c8968f7f8223..074fd18bd2ad7 100644 --- a/doc/source/whatsnew/v1.3.0.rst +++ b/doc/source/whatsnew/v1.3.0.rst @@ -143,6 +143,7 @@ Other enhancements - :class:`RangeIndex` can now be constructed by passing a ``range`` object directly e.g. ``pd.RangeIndex(range(3))`` (:issue:`12067`) - :meth:`round` being enabled for the nullable integer and floating dtypes (:issue:`38844`) - :meth:`pandas.read_csv` and :meth:`pandas.read_json` expose the argument ``encoding_errors`` to control how encoding errors are handled (:issue:`39450`) +- :meth:`.Styler.clear` now clears :attr:`Styler.hidden_index`, :attr:`Styler.hidden_columns` and :attr:`Styler.tooltips` as well (:issue:`40484`) .. --------------------------------------------------------------------------- From cc80c075ca991e7f07f758cabbd993c5c9361fa5 Mon Sep 17 00:00:00 2001 From: Brian Date: Mon, 29 Mar 2021 21:17:38 -0400 Subject: [PATCH 8/9] incorporating feedback from reviews on PR40664 related to #40484 --- .gitignore | 1 - doc/source/whatsnew/v1.3.0.rst | 2 +- pandas/io/formats/style.py | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index dbd3c60cec76c..b682d93efbd04 100644 --- a/.gitignore +++ b/.gitignore @@ -119,4 +119,3 @@ doc/build/html/index.html doc/tmp.sv env/ doc/source/savefig/ -virtualenvs/ diff --git a/doc/source/whatsnew/v1.3.0.rst b/doc/source/whatsnew/v1.3.0.rst index 074fd18bd2ad7..f17a76c4cfe81 100644 --- a/doc/source/whatsnew/v1.3.0.rst +++ b/doc/source/whatsnew/v1.3.0.rst @@ -143,7 +143,7 @@ Other enhancements - :class:`RangeIndex` can now be constructed by passing a ``range`` object directly e.g. ``pd.RangeIndex(range(3))`` (:issue:`12067`) - :meth:`round` being enabled for the nullable integer and floating dtypes (:issue:`38844`) - :meth:`pandas.read_csv` and :meth:`pandas.read_json` expose the argument ``encoding_errors`` to control how encoding errors are handled (:issue:`39450`) -- :meth:`.Styler.clear` now clears :attr:`Styler.hidden_index`, :attr:`Styler.hidden_columns` and :attr:`Styler.tooltips` as well (:issue:`40484`) +- :meth:`.Styler.clear` now clears :attr:`Styler.hidden_index` and :attr:`Styler.hidden_columns` as well (:issue:`40484`) .. --------------------------------------------------------------------------- diff --git a/pandas/io/formats/style.py b/pandas/io/formats/style.py index a67001cf1e865..fe7fc53165543 100644 --- a/pandas/io/formats/style.py +++ b/pandas/io/formats/style.py @@ -864,7 +864,6 @@ def clear(self) -> None: self.hidden_index = False self.hidden_columns = [] - self.tooltips = None # self.format and self.table_styles may be dependent on user # input in self.__init__() From 8c76581d254cf65171ca516c0acc513485a4b52a Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 31 Mar 2021 18:08:18 -0400 Subject: [PATCH 9/9] slight updated to documentation to group Styler comments together for #40484 --- doc/source/whatsnew/v1.3.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.3.0.rst b/doc/source/whatsnew/v1.3.0.rst index 64949c833bc64..78fb8838a9fa9 100644 --- a/doc/source/whatsnew/v1.3.0.rst +++ b/doc/source/whatsnew/v1.3.0.rst @@ -137,6 +137,7 @@ Other enhancements - :meth:`.Styler.apply` now more consistently accepts ndarray function returns, i.e. in all cases for ``axis`` is ``0, 1 or None`` (:issue:`39359`) - :meth:`.Styler.apply` and :meth:`.Styler.applymap` now raise errors if wrong format CSS is passed on render (:issue:`39660`) - :meth:`.Styler.format` adds keyword argument ``escape`` for optional HTML escaping (:issue:`40437`) +- :meth:`.Styler.clear` now clears :attr:`Styler.hidden_index` and :attr:`Styler.hidden_columns` as well (:issue:`40484`) - Builtin highlighting methods in :class:`Styler` have a more consistent signature and css customisability (:issue:`40242`) - :meth:`Series.loc.__getitem__` and :meth:`Series.loc.__setitem__` with :class:`MultiIndex` now raising helpful error message when indexer has too many dimensions (:issue:`35349`) - :meth:`pandas.read_stata` and :class:`StataReader` support reading data from compressed files. @@ -145,7 +146,6 @@ Other enhancements - :class:`RangeIndex` can now be constructed by passing a ``range`` object directly e.g. ``pd.RangeIndex(range(3))`` (:issue:`12067`) - :meth:`round` being enabled for the nullable integer and floating dtypes (:issue:`38844`) - :meth:`pandas.read_csv` and :meth:`pandas.read_json` expose the argument ``encoding_errors`` to control how encoding errors are handled (:issue:`39450`) -- :meth:`.Styler.clear` now clears :attr:`Styler.hidden_index` and :attr:`Styler.hidden_columns` as well (:issue:`40484`) .. ---------------------------------------------------------------------------