Skip to content

DEPR: Int64Index, UInt64Index & Float64Index #43028

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Sep 1, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix more errors + add to whatsnew v1.4.0
  • Loading branch information
topper-123 committed Sep 1, 2021
commit 84007a38b45ee09f92543c00aca11a707133d3b1
9 changes: 5 additions & 4 deletions doc/source/whatsnew/v0.20.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,12 @@ or purely non-negative, integers. Previously, handling these integers would
result in improper rounding or data-type casting, leading to incorrect results.
Notably, a new numerical index, ``UInt64Index``, has been created (:issue:`14937`)

.. ipython:: python
.. code-block:: ipython

idx = pd.UInt64Index([1, 2, 3])
df = pd.DataFrame({'A': ['a', 'b', 'c']}, index=idx)
df.index
In [1]: idx = pd.UInt64Index([1, 2, 3])
In [2]: df = pd.DataFrame({'A': ['a', 'b', 'c']}, index=idx)
In [3]: df.index
Out[3]: UInt64Index([1, 2, 3], dtype='uint64')

- Bug in converting object elements of array-like objects to unsigned 64-bit integers (:issue:`4471`, :issue:`14982`)
- Bug in ``Series.unique()`` in which unsigned 64-bit integers were causing overflow (:issue:`14721`)
Expand Down
50 changes: 42 additions & 8 deletions doc/source/whatsnew/v1.4.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,20 @@ It is now possible to create an index of any numpy int/uint/float dtype using th
pd.NumericIndex([1, 2, 3], dtype="float32")

In order to maintain backwards compatibility, calls to the base :class:`Index` will in
pandas 1.x. return :class:`Int64Index`, :class:`UInt64Index` and :class:`Float64Index`.
pandas 1.x. return :class:`Int64Index`, :class:`UInt64Index` and :class:`Float64Index`, where relevant.
For example, the code below returns an ``Int64Index`` with dtype ``int64``:

.. code-block:: ipython

In [1]: pd.Index([1, 2, 3], dtype="int8")
Int64Index([1, 2, 3], dtype='int64')

but will in Pandas 2.0 return a :class:`NumericIndex` with dtype ``int8``.

More generally, for the duration of Pandas 1.x, all operations that until now have
returned :class:`Int64Index`, :class:`UInt64Index` and :class:`Float64Index` will
continue to so. This means, that in order to use ``NumericIndex``, you will have to call
``NumericIndex`` explicitly. For example the below series will have an ``Int64Index``:
continue to so. This means, that in order to use ``NumericIndex`` in Pandas 1.x, you
will have to call ``NumericIndex`` explicitly. For example the below series will have an ``Int64Index``:

.. code-block:: ipython

Expand All @@ -59,9 +61,9 @@ Instead, if you want to use a ``NumericIndex`` in Pandas 1.x, you should do:

In Pandas 2.0, :class:`NumericIndex` will become the default numeric index type and
``Int64Index``, ``UInt64Index`` and ``Float64Index`` are therefore deprecated and will
be removed in pandas 2.0.
be removed in pandas 2.0, see :ref:`here <whatsnew_140.deprecations.int64_uint64_float64index>` for more.

See :ref:`here <advanced.numericindex>` for more.
See :ref:`here <advanced.numericindex>` for more about :class:`NumericIndex`.

.. _whatsnew_140.enhancements.styler:

Expand Down Expand Up @@ -224,9 +226,41 @@ Other API changes

Deprecations
~~~~~~~~~~~~
- Deprecated :class:`Int64Index` (:issue:`43028`).
- Deprecated :class:`UInt64Index` (:issue:`43028`).
- Deprecated :class:`Float64Index` (:issue:`43028`).

.. _whatsnew_140.deprecations.int64_uint64_float64index:

Deprecated Int64Index, UInt64Index & Float64Index
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
:class:`Int64Index`, :class:`UInt64Index` (:issue:`43028`) and :class:`Float64Index` have
been deprecated in favor of the new :class:`NumericIndex` (:issue:`43028`).

For the duration of Pandas 1.x, in order to maintain backward compatibility, calls to
:class:`Index` will continue to return :class:`Int64Index`, :class:`UInt64Index` and :class:`Float64Index`
when given numeric data, but in Pandas 2.0, a :class:`NumericIndex` will be returned.

*Current behavior (Pandas 1.x)*:

.. code-block:: ipython

In [1]: pd.Index([1, 2, 3], dtype="int32")
Out [1]: Int64Index([1, 2, 3], dtype='int64')
In [1]: pd.Index([1, 2, 3], dtype="uint64")
Out [1]: UInt64Index([1, 2, 3], dtype='uint64')

*Future behavior (Pandas 2.0)*:

.. code-block:: ipython

In [3]: pd.Index([1, 2, 3], dtype="int32")
Out [3]: NumericIndex([1, 2, 3], dtype='int32')
In [4]: pd.Index([1, 2, 3], dtype="uint64")
Out [4]: NumericIndex([1, 2, 3], dtype='uint64')


.. _whatsnew_140.deprecations.other:

Other Deprecations
^^^^^^^^^^^^^^^^^^
- Deprecated :meth:`Index.is_type_compatible` (:issue:`42113`)
- Deprecated ``method`` argument in :meth:`Index.get_loc`, use ``index.get_indexer([label], method=...)`` instead (:issue:`42269`)
- Deprecated treating integer keys in :meth:`Series.__setitem__` as positional when the index is a :class:`Float64Index` not containing the key, a :class:`IntervalIndex` with no entries containing the key, or a :class:`MultiIndex` with leading :class:`Float64Index` level not containing the key (:issue:`33469`)
Expand Down
5 changes: 3 additions & 2 deletions pandas/tests/groupby/test_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
bdate_range,
)
import pandas._testing as tm
from pandas.core.api import Int64Index


def test_apply_issues():
Expand Down Expand Up @@ -785,10 +786,10 @@ def test_apply_with_mixed_types():

def test_func_returns_object():
# GH 28652
df = DataFrame({"a": [1, 2]}, index=pd.Int64Index([1, 2]))
df = DataFrame({"a": [1, 2]}, index=Int64Index([1, 2]))
result = df.groupby("a").apply(lambda g: g.index)
expected = Series(
[pd.Int64Index([1]), pd.Int64Index([2])], index=pd.Int64Index([1, 2], name="a")
[Int64Index([1]), Int64Index([2])], index=Int64Index([1, 2], name="a")
)

tm.assert_series_equal(result, expected)
Expand Down
10 changes: 7 additions & 3 deletions pandas/tests/groupby/test_grouping.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
date_range,
)
import pandas._testing as tm
from pandas.core.api import (
Float64Index,
Int64Index,
)
from pandas.core.groupby.grouper import Grouping

# selection
Expand Down Expand Up @@ -634,11 +638,11 @@ def test_list_grouper_with_nat(self):
),
(
"agg",
Series(name=2, dtype=np.float64, index=pd.Float64Index([], name=1)),
Series(name=2, dtype=np.float64, index=Float64Index([], name=1)),
),
(
"apply",
Series(name=2, dtype=np.float64, index=pd.Float64Index([], name=1)),
Series(name=2, dtype=np.float64, index=Float64Index([], name=1)),
),
],
)
Expand Down Expand Up @@ -702,7 +706,7 @@ def test_groupby_multiindex_level_empty(self):
empty = df[df.value < 0]
result = empty.groupby("id").sum()
expected = DataFrame(
dtype="float64", columns=["value"], index=pd.Int64Index([], name="id")
dtype="float64", columns=["value"], index=Int64Index([], name="id")
)
tm.assert_frame_equal(result, expected)

Expand Down
5 changes: 3 additions & 2 deletions pandas/tests/groupby/test_min_max.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
Series,
)
import pandas._testing as tm
from pandas.core.api import Int64Index


def test_max_min_non_numeric():
Expand Down Expand Up @@ -120,7 +121,7 @@ def test_groupby_aggregate_period_column(func):
df = DataFrame({"a": groups, "b": periods})

result = getattr(df.groupby("a")["b"], func)()
idx = pd.Int64Index([1, 2], name="a")
idx = Int64Index([1, 2], name="a")
expected = Series(periods, index=idx, name="b")

tm.assert_series_equal(result, expected)
Expand All @@ -134,7 +135,7 @@ def test_groupby_aggregate_period_frame(func):
df = DataFrame({"a": groups, "b": periods})

result = getattr(df.groupby("a"), func)()
idx = pd.Int64Index([1, 2], name="a")
idx = Int64Index([1, 2], name="a")
expected = DataFrame({"b": periods}, index=idx)

tm.assert_frame_equal(result, expected)
Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/groupby/test_pipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Index,
)
import pandas._testing as tm
from pandas.core.api import Int64Index


def test_pipe():
Expand Down Expand Up @@ -76,6 +77,6 @@ def h(df, arg3):
ser = pd.Series([1, 1, 2, 2, 3, 3])
result = ser.groupby(ser).pipe(lambda grp: grp.sum() * grp.count())

expected = pd.Series([4, 8, 12], index=pd.Int64Index([1, 2, 3]))
expected = pd.Series([4, 8, 12], index=Int64Index([1, 2, 3]))

tm.assert_series_equal(result, expected)
3 changes: 2 additions & 1 deletion pandas/tests/resample/test_resampler_grouper.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
Timestamp,
)
import pandas._testing as tm
from pandas.core.api import Int64Index
from pandas.core.indexes.datetimes import date_range

test_frame = DataFrame(
Expand Down Expand Up @@ -324,7 +325,7 @@ def test_consistency_with_window():

# consistent return values with window
df = test_frame
expected = pd.Int64Index([1, 2, 3], name="A")
expected = Int64Index([1, 2, 3], name="A")
result = df.groupby("A").resample("2s").mean()
assert result.index.nlevels == 2
tm.assert_index_equal(result.index.levels[0], expected)
Expand Down