From 6d7bcacde0b99bee275fc2edd1332e551ea585da Mon Sep 17 00:00:00 2001 From: Chaarvi Bansal Date: Fri, 19 Jul 2024 22:36:35 +0100 Subject: [PATCH 1/3] update documentation --- pandas/core/reshape/tile.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pandas/core/reshape/tile.py b/pandas/core/reshape/tile.py index 0052bcfe09147..87faf4fbb547e 100644 --- a/pandas/core/reshape/tile.py +++ b/pandas/core/reshape/tile.py @@ -142,12 +142,17 @@ def cut( fixed set of values. Series : One-dimensional array with axis labels (including time series). IntervalIndex : Immutable Index implementing an ordered, sliceable set. + np.histogram_bin_edges: Function to calculate only the edges of the bins + used by the histogram function. Notes ----- Any NA values will be NA in the result. Out of bounds values will be NA in the resulting Series or Categorical object. + np.histogram_bin_edges can be used along with cut to calculate bins according + to some predefined methods. + Reference :ref:`the user guide ` for more examples. Examples @@ -239,6 +244,16 @@ def cut( >>> pd.cut([0, 0.5, 1.5, 2.5, 4.5], bins) [NaN, (0.0, 1.0], NaN, (2.0, 3.0], (4.0, 5.0]] Categories (3, interval[int64, right]): [(0, 1] < (2, 3] < (4, 5]] + + Using np.histogram_bin_edges with cut + + >>> pd.cut( + ... np.array([1, 7, 5, 4]), + ... bins=np.histogram_bin_edges(np.array([1, 7, 5, 4]), bins="auto"), + ... ) + ... # doctest: +ELLIPSIS + [NaN, (5.0, 7.0], (3.0, 5.0], (3.0, 5.0]] + Categories (3, interval[float64, right]): [(1.0, 3.0] < (3.0, 5.0] < (5.0, 7.0]] """ # NOTE: this binning code is changed a bit from histogram for var(x) == 0 From 54d2058659c054f82398a1a5db1c9b32319627f8 Mon Sep 17 00:00:00 2001 From: Chaarvi Bansal <49508554+chaarvii@users.noreply.github.com> Date: Sat, 20 Jul 2024 11:05:51 +0100 Subject: [PATCH 2/3] Update pandas/core/reshape/tile.py Co-authored-by: Asish Mahapatra --- pandas/core/reshape/tile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/reshape/tile.py b/pandas/core/reshape/tile.py index 87faf4fbb547e..086a7473d5d7f 100644 --- a/pandas/core/reshape/tile.py +++ b/pandas/core/reshape/tile.py @@ -142,7 +142,7 @@ def cut( fixed set of values. Series : One-dimensional array with axis labels (including time series). IntervalIndex : Immutable Index implementing an ordered, sliceable set. - np.histogram_bin_edges: Function to calculate only the edges of the bins + numpy.histogram_bin_edges: Function to calculate only the edges of the bins used by the histogram function. Notes From e4eae7f277a868ed728c3604c94fb5f6e52461f2 Mon Sep 17 00:00:00 2001 From: Chaarvi Bansal <49508554+chaarvii@users.noreply.github.com> Date: Mon, 22 Jul 2024 18:54:21 +0100 Subject: [PATCH 3/3] Update pandas/core/reshape/tile.py Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> --- pandas/core/reshape/tile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/reshape/tile.py b/pandas/core/reshape/tile.py index 086a7473d5d7f..18517199f073c 100644 --- a/pandas/core/reshape/tile.py +++ b/pandas/core/reshape/tile.py @@ -150,7 +150,7 @@ def cut( Any NA values will be NA in the result. Out of bounds values will be NA in the resulting Series or Categorical object. - np.histogram_bin_edges can be used along with cut to calculate bins according + ``numpy.histogram_bin_edges`` can be used along with cut to calculate bins according to some predefined methods. Reference :ref:`the user guide ` for more examples.