Skip to content

DEPR: lookup, append #49481

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 10 commits into from
Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
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
20 changes: 0 additions & 20 deletions asv_bench/benchmarks/frame_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,6 @@ def time_frame_get_numeric_data(self):
self.df._get_numeric_data()


class Lookup:
def setup(self):
self.df = DataFrame(np.random.randn(10000, 8), columns=list("abcdefgh"))
self.df["foo"] = "bar"
self.row_labels = list(self.df.index[::10])[:900]
self.col_labels = list(self.df.columns) * 100
self.row_labels_all = np.array(
list(self.df.index) * len(self.df.columns), dtype="object"
)
self.col_labels_all = np.array(
list(self.df.columns) * len(self.df.index), dtype="object"
)

def time_frame_fancy_lookup(self):
self.df.lookup(self.row_labels, self.col_labels)

def time_frame_fancy_lookup_all(self):
self.df.lookup(self.row_labels_all, self.col_labels_all)


class Reindex:
def setup(self):
N = 10**3
Expand Down
3 changes: 0 additions & 3 deletions doc/redirects.csv
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,6 @@ generated/pandas.DataFrame.aggregate,../reference/api/pandas.DataFrame.aggregate
generated/pandas.DataFrame.align,../reference/api/pandas.DataFrame.align
generated/pandas.DataFrame.all,../reference/api/pandas.DataFrame.all
generated/pandas.DataFrame.any,../reference/api/pandas.DataFrame.any
generated/pandas.DataFrame.append,../reference/api/pandas.DataFrame.append
generated/pandas.DataFrame.apply,../reference/api/pandas.DataFrame.apply
generated/pandas.DataFrame.applymap,../reference/api/pandas.DataFrame.applymap
generated/pandas.DataFrame.as_blocks,../reference/api/pandas.DataFrame.as_blocks
Expand Down Expand Up @@ -408,7 +407,6 @@ generated/pandas.DataFrame.last,../reference/api/pandas.DataFrame.last
generated/pandas.DataFrame.last_valid_index,../reference/api/pandas.DataFrame.last_valid_index
generated/pandas.DataFrame.le,../reference/api/pandas.DataFrame.le
generated/pandas.DataFrame.loc,../reference/api/pandas.DataFrame.loc
generated/pandas.DataFrame.lookup,../reference/api/pandas.DataFrame.lookup
generated/pandas.DataFrame.lt,../reference/api/pandas.DataFrame.lt
generated/pandas.DataFrame.mask,../reference/api/pandas.DataFrame.mask
generated/pandas.DataFrame.max,../reference/api/pandas.DataFrame.max
Expand Down Expand Up @@ -919,7 +917,6 @@ generated/pandas.Series.aggregate,../reference/api/pandas.Series.aggregate
generated/pandas.Series.align,../reference/api/pandas.Series.align
generated/pandas.Series.all,../reference/api/pandas.Series.all
generated/pandas.Series.any,../reference/api/pandas.Series.any
generated/pandas.Series.append,../reference/api/pandas.Series.append
generated/pandas.Series.apply,../reference/api/pandas.Series.apply
generated/pandas.Series.argmax,../reference/api/pandas.Series.argmax
generated/pandas.Series.argmin,../reference/api/pandas.Series.argmin
Expand Down
2 changes: 0 additions & 2 deletions doc/source/reference/frame.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ Indexing, iteration
DataFrame.keys
DataFrame.iterrows
DataFrame.itertuples
DataFrame.lookup
DataFrame.pop
DataFrame.tail
DataFrame.xs
Expand Down Expand Up @@ -250,7 +249,6 @@ Combining / comparing / joining / merging
.. autosummary::
:toctree: api/

DataFrame.append
DataFrame.assign
DataFrame.compare
DataFrame.join
Expand Down
2 changes: 1 addition & 1 deletion doc/source/user_guide/indexing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1559,7 +1559,7 @@ For instance:
df.reindex(cols, axis=1).to_numpy()[np.arange(len(df)), idx]

Formerly this could be achieved with the dedicated ``DataFrame.lookup`` method
which was deprecated in version 1.2.0.
which was deprecated in version 1.2.0 and removed in version 2.0.0.

.. _indexing.class:

Expand Down
2 changes: 2 additions & 0 deletions doc/source/whatsnew/v2.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ Removal of prior version deprecations/changes
- Removed deprecated :meth:`DataFrame._AXIS_NUMBERS`, :meth:`DataFrame._AXIS_NAMES`, :meth:`Series._AXIS_NUMBERS`, :meth:`Series._AXIS_NAMES` (:issue:`33637`)
- Removed deprecated :meth:`Index.to_native_types`, use ``obj.astype(str)`` instead (:issue:`36418`)
- Removed deprecated :meth:`Series.iteritems`, :meth:`DataFrame.iteritems`, use ``obj.items`` instead (:issue:`45321`)
- Removed deprecated :meth:`DataFrame.lookup` (:issue:`35224`)
- Removed deprecated :meth:`Series.append`, :meth:`DataFrame.append`, use :func:`concat` instead (:issue:`35407`)
- Removed deprecated :meth:`DatetimeIndex.union_many` (:issue:`45018`)
- Removed deprecated ``weekofyear`` and ``week`` attributes of :class:`DatetimeArray`, :class:`DatetimeIndex` and ``dt`` accessor in favor of ``isocalendar().week`` (:issue:`33595`)
- Removed deprecated :meth:`RangeIndex._start`, :meth:`RangeIndex._stop`, :meth:`RangeIndex._step`, use ``start``, ``stop``, ``step`` instead (:issue:`30482`)
Expand Down
175 changes: 0 additions & 175 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -4870,69 +4870,6 @@ def _series(self):
for idx, item in enumerate(self.columns)
}

def lookup(
self, row_labels: Sequence[IndexLabel], col_labels: Sequence[IndexLabel]
) -> np.ndarray:
"""
Label-based "fancy indexing" function for DataFrame.

.. deprecated:: 1.2.0
DataFrame.lookup is deprecated,
use pandas.factorize and NumPy indexing instead.
For further details see
:ref:`Looking up values by index/column labels <indexing.lookup>`.

Given equal-length arrays of row and column labels, return an
array of the values corresponding to each (row, col) pair.

Parameters
----------
row_labels : sequence
The row labels to use for lookup.
col_labels : sequence
The column labels to use for lookup.

Returns
-------
numpy.ndarray
The found values.
"""
msg = (
"The 'lookup' method is deprecated and will be "
"removed in a future version. "
"You can use DataFrame.melt and DataFrame.loc "
"as a substitute."
)
warnings.warn(msg, FutureWarning, stacklevel=find_stack_level())

n = len(row_labels)
if n != len(col_labels):
raise ValueError("Row labels must have same size as column labels")
if not (self.index.is_unique and self.columns.is_unique):
# GH#33041
raise ValueError("DataFrame.lookup requires unique index and columns")

thresh = 1000
if not self._is_mixed_type or n > thresh:
values = self.values
ridx = self.index.get_indexer(row_labels)
cidx = self.columns.get_indexer(col_labels)
if (ridx == -1).any():
raise KeyError("One or more row labels was not found")
if (cidx == -1).any():
raise KeyError("One or more column labels was not found")
flat_index = ridx * len(self.columns) + cidx
result = values.flat[flat_index]
else:
result = np.empty(n, dtype="O")
for i, (r, c) in enumerate(zip(row_labels, col_labels)):
result[i] = self._get_value(r, c)

if is_object_dtype(result):
result = lib.maybe_convert_objects(result)

return result

# ----------------------------------------------------------------------
# Reindexing and alignment

Expand Down Expand Up @@ -9563,118 +9500,6 @@ def infer(x):
# ----------------------------------------------------------------------
# Merging / joining methods

def append(
self,
other,
ignore_index: bool = False,
verify_integrity: bool = False,
sort: bool = False,
) -> DataFrame:
"""
Append rows of `other` to the end of caller, returning a new object.

.. deprecated:: 1.4.0
Use :func:`concat` instead. For further details see
:ref:`whatsnew_140.deprecations.frame_series_append`

Columns in `other` that are not in the caller are added as new columns.

Parameters
----------
other : DataFrame or Series/dict-like object, or list of these
The data to append.
ignore_index : bool, default False
If True, the resulting axis will be labeled 0, 1, …, n - 1.
verify_integrity : bool, default False
If True, raise ValueError on creating index with duplicates.
sort : bool, default False
Sort columns if the columns of `self` and `other` are not aligned.

.. versionchanged:: 1.0.0

Changed to not sort by default.

Returns
-------
DataFrame
A new DataFrame consisting of the rows of caller and the rows of `other`.

See Also
--------
concat : General function to concatenate DataFrame or Series objects.

Notes
-----
If a list of dict/series is passed and the keys are all contained in
the DataFrame's index, the order of the columns in the resulting
DataFrame will be unchanged.

Iteratively appending rows to a DataFrame can be more computationally
intensive than a single concatenate. A better solution is to append
those rows to a list and then concatenate the list with the original
DataFrame all at once.

Examples
--------
>>> df = pd.DataFrame([[1, 2], [3, 4]], columns=list('AB'), index=['x', 'y'])
>>> df
A B
x 1 2
y 3 4
>>> df2 = pd.DataFrame([[5, 6], [7, 8]], columns=list('AB'), index=['x', 'y'])
>>> df.append(df2)
A B
x 1 2
y 3 4
x 5 6
y 7 8

With `ignore_index` set to True:

>>> df.append(df2, ignore_index=True)
A B
0 1 2
1 3 4
2 5 6
3 7 8

The following, while not recommended methods for generating DataFrames,
show two ways to generate a DataFrame from multiple data sources.

Less efficient:

>>> df = pd.DataFrame(columns=['A'])
>>> for i in range(5):
... df = df.append({'A': i}, ignore_index=True)
>>> df
A
0 0
1 1
2 2
3 3
4 4

More efficient:

>>> pd.concat([pd.DataFrame([i], columns=['A']) for i in range(5)],
... ignore_index=True)
A
0 0
1 1
2 2
3 3
4 4
"""
warnings.warn(
"The frame.append method is deprecated "
"and will be removed from pandas in a future version. "
"Use pandas.concat instead.",
FutureWarning,
stacklevel=find_stack_level(),
)

return self._append(other, ignore_index, verify_integrity, sort)

def _append(
self,
other,
Expand Down
86 changes: 0 additions & 86 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2976,92 +2976,6 @@ def searchsorted( # type: ignore[override]
# -------------------------------------------------------------------
# Combination

def append(
self, to_append, ignore_index: bool = False, verify_integrity: bool = False
) -> Series:
"""
Concatenate two or more Series.

.. deprecated:: 1.4.0
Use :func:`concat` instead. For further details see
:ref:`whatsnew_140.deprecations.frame_series_append`

Parameters
----------
to_append : Series or list/tuple of Series
Series to append with self.
ignore_index : bool, default False
If True, the resulting axis will be labeled 0, 1, …, n - 1.
verify_integrity : bool, default False
If True, raise Exception on creating index with duplicates.

Returns
-------
Series
Concatenated Series.

See Also
--------
concat : General function to concatenate DataFrame or Series objects.

Notes
-----
Iteratively appending to a Series can be more computationally intensive
than a single concatenate. A better solution is to append values to a
list and then concatenate the list with the original Series all at
once.

Examples
--------
>>> s1 = pd.Series([1, 2, 3])
>>> s2 = pd.Series([4, 5, 6])
>>> s3 = pd.Series([4, 5, 6], index=[3, 4, 5])
>>> s1.append(s2)
0 1
1 2
2 3
0 4
1 5
2 6
dtype: int64

>>> s1.append(s3)
0 1
1 2
2 3
3 4
4 5
5 6
dtype: int64

With `ignore_index` set to True:

>>> s1.append(s2, ignore_index=True)
0 1
1 2
2 3
3 4
4 5
5 6
dtype: int64

With `verify_integrity` set to True:

>>> s1.append(s2, verify_integrity=True)
Traceback (most recent call last):
...
ValueError: Indexes have overlapping values: [0, 1, 2]
"""
warnings.warn(
"The series.append method is deprecated "
"and will be removed from pandas in a future version. "
"Use pandas.concat instead.",
FutureWarning,
stacklevel=find_stack_level(),
)

return self._append(to_append, ignore_index, verify_integrity)

def _append(
self, to_append, ignore_index: bool = False, verify_integrity: bool = False
):
Expand Down
Loading