Skip to content

Commit 878ba61

Browse files
mikeronayneyeshsurya
authored andcommitted
BUG: to_string truncation column with index=False (pandas-dev#40907)
1 parent dbf5d6a commit 878ba61

File tree

1 file changed

+10
-96
lines changed

1 file changed

+10
-96
lines changed

doc/source/whatsnew/v1.3.0.rst

+10-96
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,7 @@ Other enhancements
194194
- :func:`to_numeric` now supports downcasting of nullable ``ExtensionDtype`` objects (:issue:`33013`)
195195
- Add support for dict-like names in :class:`MultiIndex.set_names` and :class:`MultiIndex.rename` (:issue:`20421`)
196196
- :func:`pandas.read_excel` can now auto detect .xlsb files (:issue:`35416`)
197-
- :class:`pandas.ExcelWriter` now accepts an ``if_sheet_exists`` parameter to control the behaviour of append mode when writing to existing sheets (:issue:`40230`)
198-
- :meth:`.Rolling.sum`, :meth:`.Expanding.sum`, :meth:`.Rolling.mean`, :meth:`.Expanding.mean`, :meth:`.ExponentialMovingWindow.mean`, :meth:`.Rolling.median`, :meth:`.Expanding.median`, :meth:`.Rolling.max`, :meth:`.Expanding.max`, :meth:`.Rolling.min`, and :meth:`.Expanding.min` now support ``Numba`` execution with the ``engine`` keyword (:issue:`38895`, :issue:`41267`)
197+
- :meth:`.Rolling.sum`, :meth:`.Expanding.sum`, :meth:`.Rolling.mean`, :meth:`.Expanding.mean`, :meth:`.Rolling.median`, :meth:`.Expanding.median`, :meth:`.Rolling.max`, :meth:`.Expanding.max`, :meth:`.Rolling.min`, and :meth:`.Expanding.min` now support ``Numba`` execution with the ``engine`` keyword (:issue:`38895`)
199198
- :meth:`DataFrame.apply` can now accept NumPy unary operators as strings, e.g. ``df.apply("sqrt")``, which was already the case for :meth:`Series.apply` (:issue:`39116`)
200199
- :meth:`DataFrame.apply` can now accept non-callable DataFrame properties as strings, e.g. ``df.apply("size")``, which was already the case for :meth:`Series.apply` (:issue:`39116`)
201200
- :meth:`DataFrame.applymap` can now accept kwargs to pass on to func (:issue:`39987`)
@@ -220,8 +219,6 @@ Other enhancements
220219
- :meth:`pandas.read_csv` and :meth:`pandas.read_json` expose the argument ``encoding_errors`` to control how encoding errors are handled (:issue:`39450`)
221220
- :meth:`.GroupBy.any` and :meth:`.GroupBy.all` use Kleene logic with nullable data types (:issue:`37506`)
222221
- :meth:`.GroupBy.any` and :meth:`.GroupBy.all` return a ``BooleanDtype`` for columns with nullable data types (:issue:`33449`)
223-
- Constructing a :class:`DataFrame` or :class:`Series` with the ``data`` argument being a Python iterable that is *not* a NumPy ``ndarray`` consisting of NumPy scalars will now result in a dtype with a precision the maximum of the NumPy scalars; this was already the case when ``data`` is a NumPy ``ndarray`` (:issue:`40908`)
224-
- Add keyword ``sort`` to :func:`pivot_table` to allow non-sorting of the result (:issue:`39143`)
225222
-
226223

227224
.. ---------------------------------------------------------------------------
@@ -233,38 +230,6 @@ Notable bug fixes
233230

234231
These are bug fixes that might have notable behavior changes.
235232

236-
``Categorical.unique`` now always maintains same dtype as original
237-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
238-
239-
Previously, when calling :meth:`~Categorical.unique` with categorical data, unused categories in the new array
240-
would be removed, meaning that the dtype of the new array would be different than the
241-
original, if some categories are not present in the unique array (:issue:`18291`)
242-
243-
As an example of this, given:
244-
245-
.. ipython:: python
246-
247-
dtype = pd.CategoricalDtype(['bad', 'neutral', 'good'], ordered=True)
248-
cat = pd.Categorical(['good', 'good', 'bad', 'bad'], dtype=dtype)
249-
original = pd.Series(cat)
250-
unique = original.unique()
251-
252-
*pandas < 1.3.0*:
253-
254-
.. code-block:: ipython
255-
256-
In [1]: unique
257-
['good', 'bad']
258-
Categories (2, object): ['bad' < 'good']
259-
In [2]: original.dtype == unique.dtype
260-
False
261-
262-
*pandas >= 1.3.0*
263-
264-
.. ipython:: python
265-
266-
unique
267-
original.dtype == unique.dtype
268233

269234
Preserve dtypes in :meth:`~pandas.DataFrame.combine_first`
270235
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -296,36 +261,6 @@ Preserve dtypes in :meth:`~pandas.DataFrame.combine_first`
296261
297262
combined.dtypes
298263
299-
Group by methods agg and transform no longer changes return dtype for callables
300-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
301-
302-
Previously the methods :meth:`.DataFrameGroupBy.aggregate`,
303-
:meth:`.SeriesGroupBy.aggregate`, :meth:`.DataFrameGroupBy.transform`, and
304-
:meth:`.SeriesGroupBy.transform` might cast the result dtype when the argument ``func``
305-
is callable, possibly leading to undesirable results (:issue:`21240`). The cast would
306-
occur if the result is numeric and casting back to the input dtype does not change any
307-
values as measured by ``np.allclose``. Now no such casting occurs.
308-
309-
.. ipython:: python
310-
311-
df = pd.DataFrame({'key': [1, 1], 'a': [True, False], 'b': [True, True]})
312-
df
313-
314-
*pandas 1.2.x*
315-
316-
.. code-block:: ipython
317-
318-
In [5]: df.groupby('key').agg(lambda x: x.sum())
319-
Out[5]:
320-
a b
321-
key
322-
1 True 2
323-
324-
*pandas 1.3.0*
325-
326-
.. ipython:: python
327-
328-
df.groupby('key').agg(lambda x: x.sum())
329264
330265
Try operating inplace when setting values with ``loc`` and ``iloc``
331266
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -543,7 +478,7 @@ If installed, we now require:
543478
+-----------------+-----------------+----------+---------+
544479
| numexpr | 2.6.8 | | |
545480
+-----------------+-----------------+----------+---------+
546-
| pytest (dev) | 6.0 | | X |
481+
| pytest (dev) | 5.0.1 | | |
547482
+-----------------+-----------------+----------+---------+
548483
| mypy (dev) | 0.800 | | X |
549484
+-----------------+-----------------+----------+---------+
@@ -634,11 +569,8 @@ Deprecations
634569
- Deprecated :meth:`.Styler.set_na_rep` and :meth:`.Styler.set_precision` in favour of :meth:`.Styler.format` with ``na_rep`` and ``precision`` as existing and new input arguments respectively (:issue:`40134`, :issue:`40425`)
635570
- Deprecated allowing partial failure in :meth:`Series.transform` and :meth:`DataFrame.transform` when ``func`` is list-like or dict-like and raises anything but ``TypeError``; ``func`` raising anything but a ``TypeError`` will raise in a future version (:issue:`40211`)
636571
- Deprecated support for ``np.ma.mrecords.MaskedRecords`` in the :class:`DataFrame` constructor, pass ``{name: data[name] for name in data.dtype.names}`` instead (:issue:`40363`)
637-
- Deprecated using :func:`merge` or :func:`join` on a different number of levels (:issue:`34862`)
638572
- Deprecated the use of ``**kwargs`` in :class:`.ExcelWriter`; use the keyword argument ``engine_kwargs`` instead (:issue:`40430`)
639573
- Deprecated the ``level`` keyword for :class:`DataFrame` and :class:`Series` aggregations; use groupby instead (:issue:`39983`)
640-
- The ``inplace`` parameter of :meth:`Categorical.remove_categories`, :meth:`Categorical.add_categories`, :meth:`Categorical.reorder_categories`, :meth:`Categorical.rename_categories` is deprecated and will be removed in a future version (:issue:`37643`)
641-
- Deprecated :func:`merge` producing duplicated columns through the ``suffixes`` keyword and already existing columns (:issue:`22818`)
642574

643575
.. ---------------------------------------------------------------------------
644576
@@ -660,10 +592,7 @@ Performance improvements
660592
- Performance improvement in :class:`Styler` where render times are more than 50% reduced (:issue:`39972` :issue:`39952`)
661593
- Performance improvement in :meth:`core.window.ewm.ExponentialMovingWindow.mean` with ``times`` (:issue:`39784`)
662594
- Performance improvement in :meth:`.GroupBy.apply` when requiring the python fallback implementation (:issue:`40176`)
663-
- Performance improvement in the conversion of pyarrow boolean array to a pandas nullable boolean array (:issue:`41051`)
664595
- Performance improvement for concatenation of data with type :class:`CategoricalDtype` (:issue:`40193`)
665-
- Performance improvement in :meth:`.GroupBy.cummin` and :meth:`.GroupBy.cummax` with nullable data types (:issue:`37493`)
666-
- Performance improvement in :meth:`Series.nunique` with nan values (:issue:`40865`)
667596

668597
.. ---------------------------------------------------------------------------
669598
@@ -723,8 +652,7 @@ Numeric
723652
- Bug in :meth:`DataFrame.apply` and :meth:`DataFrame.agg` when passed argument ``func="size"`` would operate on the entire ``DataFrame`` instead of rows or columns (:issue:`39934`)
724653
- Bug in :meth:`DataFrame.transform` would raise ``SpecificationError`` when passed a dictionary and columns were missing; will now raise a ``KeyError`` instead (:issue:`40004`)
725654
- Bug in :meth:`DataFrameGroupBy.rank` giving incorrect results with ``pct=True`` and equal values between consecutive groups (:issue:`40518`)
726-
- Bug in :meth:`Series.count` would result in an ``int32`` result on 32-bit platforms when argument ``level=None`` (:issue:`40908`)
727-
- Bug in :meth:`Series.clip` would fail if series contains NA values and has nullable int or float as a data type (:issue:`40851`)
655+
-
728656

729657
Conversion
730658
^^^^^^^^^^
@@ -734,14 +662,13 @@ Conversion
734662
- Bug in :class:`DataFrame` failing to raise ``TypeError`` when constructing from a ``frozenset`` (:issue:`40163`)
735663
- Bug in :class:`Index` construction silently ignoring a passed ``dtype`` when the data cannot be cast to that dtype (:issue:`21311`)
736664
- Bug in :meth:`StringArray.astype` falling back to numpy and raising when converting to ``dtype='categorical'`` (:issue:`40450`)
737-
- Bug in :func:`factorize` where, when given an array with a numeric numpy dtype lower than int64, uint64 and float64, the unique values did not keep their original dtype (:issue:`41132`)
738665
- Bug in :class:`DataFrame` construction with a dictionary containing an arraylike with ``ExtensionDtype`` and ``copy=True`` failing to make a copy (:issue:`38939`)
739-
- Bug in :meth:`qcut` raising error when taking ``Float64DType`` as input (:issue:`40730`)
666+
-
740667

741668
Strings
742669
^^^^^^^
743670

744-
- Bug in the conversion from ``pyarrow.ChunkedArray`` to :class:`~arrays.StringArray` when the original had zero chunks (:issue:`41040`)
671+
-
745672
-
746673

747674
Interval
@@ -780,7 +707,6 @@ Indexing
780707
- Bug in :meth:`RangeIndex.append` where a single object of length 1 was concatenated incorrectly (:issue:`39401`)
781708
- Bug in setting ``numpy.timedelta64`` values into an object-dtype :class:`Series` using a boolean indexer (:issue:`39488`)
782709
- Bug in setting numeric values into a into a boolean-dtypes :class:`Series` using ``at`` or ``iat`` failing to cast to object-dtype (:issue:`39582`)
783-
- Bug in :meth:`DataFrame.__setitem__` and :meth:`DataFrame.iloc.__setitem__` raising ``ValueError`` when trying to index with a row-slice and setting a list as values (:issue:`40440`)
784710
- Bug in :meth:`DataFrame.loc.__setitem__` when setting-with-expansion incorrectly raising when the index in the expanding axis contains duplicates (:issue:`40096`)
785711
- Bug in :meth:`DataFrame.loc` incorrectly matching non-boolean index elements (:issue:`20432`)
786712
- Bug in :meth:`Series.__delitem__` with ``ExtensionDtype`` incorrectly casting to ``ndarray`` (:issue:`40386`)
@@ -791,7 +717,6 @@ Missing
791717
- Bug in :class:`Grouper` now correctly propagates ``dropna`` argument and :meth:`DataFrameGroupBy.transform` now correctly handles missing values for ``dropna=True`` (:issue:`35612`)
792718
- Bug in :func:`isna`, and :meth:`Series.isna`, :meth:`Index.isna`, :meth:`DataFrame.isna` (and the corresponding ``notna`` functions) not recognizing ``Decimal("NaN")`` objects (:issue:`39409`)
793719
- Bug in :meth:`DataFrame.fillna` not accepting dictionary for ``downcast`` keyword (:issue:`40809`)
794-
- Bug in :func:`isna` not returning a copy of the mask for nullable types, causing any subsequent mask modification to change the original array (:issue:`40935`)
795720

796721
MultiIndex
797722
^^^^^^^^^^
@@ -825,10 +750,7 @@ I/O
825750
- Bug in :func:`read_hdf` returning unexpected records when filtering on categorical string columns using ``where`` parameter (:issue:`39189`)
826751
- Bug in :func:`read_sas` raising ``ValueError`` when ``datetimes`` were null (:issue:`39725`)
827752
- Bug in :func:`read_excel` dropping empty values from single-column spreadsheets (:issue:`39808`)
828-
- Bug in :func:`read_excel` raising ``AttributeError`` with ``MultiIndex`` header followed by two empty rows and no index, and bug affecting :func:`read_excel`, :func:`read_csv`, :func:`read_table`, :func:`read_fwf`, and :func:`read_clipboard` where one blank row after a ``MultiIndex`` header with no index would be dropped (:issue:`40442`)
829753
- Bug in :meth:`DataFrame.to_string` misplacing the truncation column when ``index=False`` (:issue:`40907`)
830-
- Bug in :func:`read_orc` always raising ``AttributeError`` (:issue:`40918`)
831-
- Bug in the conversion from pyarrow to pandas (e.g. for reading Parquet) with nullable dtypes and a pyarrow array whose data buffer size is not a multiple of dtype size (:issue:`40896`)
832754

833755
Period
834756
^^^^^^
@@ -846,6 +768,8 @@ Plotting
846768
- Bug in :func:`DataFrame.plot` was showing the wrong colors in the legend if the function was called repeatedly and some calls used ``secondary_y`` and others use ``legend=False`` (:issue:`40044`)
847769

848770

771+
772+
849773
Groupby/resample/rolling
850774
^^^^^^^^^^^^^^^^^^^^^^^^
851775
- Bug in :meth:`DataFrameGroupBy.agg` and :meth:`SeriesGroupBy.agg` with :class:`PeriodDtype` columns incorrectly casting results too aggressively (:issue:`38254`)
@@ -869,21 +793,13 @@ Groupby/resample/rolling
869793
- Bug in :class:`core.window.ewm.ExponentialMovingWindow` when calling ``__getitem__`` would incorrectly raise a ``ValueError`` when providing ``times`` (:issue:`40164`)
870794
- Bug in :class:`core.window.ewm.ExponentialMovingWindow` when calling ``__getitem__`` would not retain ``com``, ``span``, ``alpha`` or ``halflife`` attributes (:issue:`40164`)
871795
- :class:`core.window.ewm.ExponentialMovingWindow` now raises a ``NotImplementedError`` when specifying ``times`` with ``adjust=False`` due to an incorrect calculation (:issue:`40098`)
872-
- Bug in :meth:`core.window.ewm.ExponentialMovingWindowGroupby.mean` where the times argument was ignored when ``engine='numba'`` (:issue:`40951`)
873-
- Bug in :meth:`core.window.ewm.ExponentialMovingWindowGroupby.mean` where the wrong times were used in case of multiple groups (:issue:`40951`)
874-
- Bug in :class:`core.window.ewm.ExponentialMovingWindowGroupby` where the times vector and values became out of sync for non-trivial groups (:issue:`40951`)
875796
- Bug in :meth:`Series.asfreq` and :meth:`DataFrame.asfreq` dropping rows when the index is not sorted (:issue:`39805`)
876797
- Bug in aggregation functions for :class:`DataFrame` not respecting ``numeric_only`` argument when ``level`` keyword was given (:issue:`40660`)
877798
- Bug in :meth:`SeriesGroupBy.aggregate` where using a user-defined function to aggregate a ``Series`` with an object-typed :class:`Index` causes an incorrect :class:`Index` shape (issue:`40014`)
878799
- Bug in :class:`core.window.RollingGroupby` where ``as_index=False`` argument in ``groupby`` was ignored (:issue:`39433`)
879800
- Bug in :meth:`.GroupBy.any` and :meth:`.GroupBy.all` raising ``ValueError`` when using with nullable type columns holding ``NA`` even with ``skipna=True`` (:issue:`40585`)
880801
- Bug in :meth:`GroupBy.cummin` and :meth:`GroupBy.cummax` incorrectly rounding integer values near the ``int64`` implementations bounds (:issue:`40767`)
881-
- Bug in :meth:`.GroupBy.rank` with nullable dtypes incorrectly raising ``TypeError`` (:issue:`41010`)
882-
- Bug in :meth:`.GroupBy.cummin` and :meth:`.GroupBy.cummax` computing wrong result with nullable data types too large to roundtrip when casting to float (:issue:`37493`)
883-
- Bug in :meth:`DataFrame.rolling` returning mean zero for all ``NaN`` window with ``min_periods=0`` if calculation is not numerical stable (:issue:`41053`)
884-
- Bug in :meth:`DataFrame.rolling` returning sum not zero for all ``NaN`` window with ``min_periods=0`` if calculation is not numerical stable (:issue:`41053`)
885-
- Bug in :meth:`SeriesGroupBy.agg` failing to retain ordered :class:`CategoricalDtype` on order-preserving aggregations (:issue:`41147`)
886-
- Bug in :meth:`DataFrameGroupBy.min` and :meth:`DataFrameGroupBy.max` with multiple object-dtype columns and ``numeric_only=False`` incorrectly raising ``ValueError`` (:issue:41111`)
802+
887803

888804
Reshaping
889805
^^^^^^^^^
@@ -904,22 +820,21 @@ Reshaping
904820
- Bug in :meth:`DataFrame.stack` not preserving ``CategoricalDtype`` in a ``MultiIndex`` (:issue:`36991`)
905821
- Bug in :func:`to_datetime` raising error when input sequence contains unhashable items (:issue:`39756`)
906822
- Bug in :meth:`Series.explode` preserving index when ``ignore_index`` was ``True`` and values were scalars (:issue:`40487`)
907-
- Bug in :func:`to_datetime` raising ``ValueError`` when :class:`Series` contains ``None`` and ``NaT`` and has more than 50 elements (:issue:`39882`)
908823

909824
Sparse
910825
^^^^^^
911826

912827
- Bug in :meth:`DataFrame.sparse.to_coo` raising ``KeyError`` with columns that are a numeric :class:`Index` without a 0 (:issue:`18414`)
913828
- Bug in :meth:`SparseArray.astype` with ``copy=False`` producing incorrect results when going from integer dtype to floating dtype (:issue:`34456`)
914-
- Implemented :meth:`SparseArray.max` and :meth:`SparseArray.min` (:issue:`40921`)
829+
-
915830

916831
ExtensionArray
917832
^^^^^^^^^^^^^^
918833

919834
- Bug in :meth:`DataFrame.where` when ``other`` is a :class:`Series` with :class:`ExtensionArray` dtype (:issue:`38729`)
920835
- Fixed bug where :meth:`Series.idxmax`, :meth:`Series.idxmin` and ``argmax/min`` fail when the underlying data is :class:`ExtensionArray` (:issue:`32749`, :issue:`33719`, :issue:`36566`)
921836
- Fixed a bug where some properties of subclasses of :class:`PandasExtensionDtype` where improperly cached (:issue:`40329`)
922-
- Bug in :meth:`DataFrame.mask` where masking a :class:`Dataframe` with an :class:`ExtensionArray` dtype raises ``ValueError`` (:issue:`40941`)
837+
-
923838

924839
Styler
925840
^^^^^^
@@ -947,7 +862,6 @@ Other
947862
- Bug in :meth:`DataFrame.equals`, :meth:`Series.equals`, :meth:`Index.equals` with object-dtype containing ``np.datetime64("NaT")`` or ``np.timedelta64("NaT")`` (:issue:`39650`)
948863
- Bug in :func:`pandas.util.show_versions` where console JSON output was not proper JSON (:issue:`39701`)
949864
- Bug in :meth:`DataFrame.convert_dtypes` incorrectly raised ValueError when called on an empty DataFrame (:issue:`40393`)
950-
- Bug in :meth:`DataFrame.clip` not interpreting missing values as no threshold (:issue:`40420`)
951865

952866
.. ---------------------------------------------------------------------------
953867

0 commit comments

Comments
 (0)