Skip to content

Commit 42a12c6

Browse files
Terji PetersenTerji Petersen
Terji Petersen
authored and
Terji Petersen
committed
Add docs
1 parent ff87ec7 commit 42a12c6

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

doc/source/whatsnew/v2.0.0.rst

+34
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,39 @@ The new behavior, as for datetime64, either gives exactly the requested dtype or
291291
ser.astype("timedelta64[s]")
292292
ser.astype("timedelta64[D]")
293293
294+
.. _whatsnew_200.api_breaking.zero_len_indexes:
295+
296+
Empty DataFrames/Series will now default to have a ``RangeIndex``
297+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
298+
299+
When users don't specify indexes or columns when instantiating :class:`DataFrame` or :class:`Series`
300+
objects, pandas infers the index type for them. Previously, if it was not possible to
301+
infer the index type from the data, pandas used to infer the index to be a :class:`RangeIndex`,
302+
except when the frame/series was empty, then the index was inferred to be an :class:`Index`
303+
with dtype `object`.
304+
305+
This has been changed, so the type of index/columns will always be :class:`RangeIndex`,
306+
when users don't declare the index and it's not possible to infer the index type from the data (:issue:`49572`).
307+
308+
*Previous behavior*:
309+
310+
.. code-block:: ipython
311+
312+
In [8]: pd.Series().index
313+
Out[8]:
314+
Index([], dtype='object')
315+
316+
In [9] pd.DataFrame().axes
317+
Out[9]:
318+
[Index([], dtype='object'), Index([], dtype='object')]
319+
320+
*New behavior*:
321+
322+
.. ipython:: python
323+
324+
pd.Series().index
325+
pd.DataFrame().axes
326+
294327
.. _whatsnew_200.api_breaking.deps:
295328

296329
Increased minimum versions for dependencies
@@ -349,6 +382,7 @@ Other API changes
349382
- :func:`read_stata` with parameter ``index_col`` set to ``None`` (the default) will now set the index on the returned :class:`DataFrame` to a :class:`RangeIndex` instead of a :class:`Int64Index` (:issue:`49745`)
350383
- Changed behavior of :class:`Index` constructor with an object-dtype ``numpy.ndarray`` containing all-``bool`` values or all-complex values, this will now retain object dtype, consistent with the :class:`Series` behavior (:issue:`49594`)
351384
- Changed behavior of :meth:`DataFrame.shift` with ``axis=1``, an integer ``fill_value``, and homogeneous datetime-like dtype, this now fills new columns with integer dtypes instead of casting to datetimelike (:issue:`49842`)
385+
- Changed behavior of :func:`read_csv`, :func:`read_json` & :func:`read_fwf`, where the index will now always be a :class:`RangeIndex`, when no index is specified. Previously the index would be a :class:`Index` with dtype `object` if the new DataFrame/Series had length 0 (:issue:`49572`)
352386
- :meth:`DataFrame.values`, :meth:`DataFrame.to_numpy`, :meth:`DataFrame.xs`, :meth:`DataFrame.reindex`, :meth:`DataFrame.fillna`, and :meth:`DataFrame.replace` no longer silently consolidate the underlying arrays; do ``df = df.copy()`` to ensure consolidation (:issue:`49356`)
353387
-
354388

0 commit comments

Comments
 (0)