diff --git a/doc/source/getting_started/comparison/comparison_with_spreadsheets.rst b/doc/source/getting_started/comparison/comparison_with_spreadsheets.rst index bdd0f7d8cfddf..19999be9b461f 100644 --- a/doc/source/getting_started/comparison/comparison_with_spreadsheets.rst +++ b/doc/source/getting_started/comparison/comparison_with_spreadsheets.rst @@ -435,13 +435,14 @@ The equivalent in pandas: Adding a row ~~~~~~~~~~~~ -Assuming we are using a :class:`~pandas.RangeIndex` (numbered ``0``, ``1``, etc.), we can use :meth:`DataFrame.append` to add a row to the bottom of a ``DataFrame``. +Assuming we are using a :class:`~pandas.RangeIndex` (numbered ``0``, ``1``, etc.), we can use :func:`concat` to add a row to the bottom of a ``DataFrame``. .. ipython:: python df - new_row = {"class": "E", "student_count": 51, "all_pass": True} - df.append(new_row, ignore_index=True) + new_row = pd.DataFrame([["E", 51, True]], + columns=["class", "student_count", "all_pass"]) + pd.concat([df, new_row]) Find and Replace diff --git a/doc/source/user_guide/10min.rst b/doc/source/user_guide/10min.rst index 4aca107b7c106..08488a33936f0 100644 --- a/doc/source/user_guide/10min.rst +++ b/doc/source/user_guide/10min.rst @@ -478,7 +478,6 @@ Concatenating pandas objects together with :func:`concat`: a row requires a copy, and may be expensive. We recommend passing a pre-built list of records to the :class:`DataFrame` constructor instead of building a :class:`DataFrame` by iteratively appending records to it. - See :ref:`Appending to dataframe ` for more. Join ~~~~ diff --git a/doc/source/user_guide/cookbook.rst b/doc/source/user_guide/cookbook.rst index 03221e71ea32a..8c2dd3ba60f13 100644 --- a/doc/source/user_guide/cookbook.rst +++ b/doc/source/user_guide/cookbook.rst @@ -929,9 +929,9 @@ Valid frequency arguments to Grouper :ref:`Timeseries ` docs. The :ref:`Join ` docs. +The :ref:`Join ` docs. -`Append two dataframes with overlapping index (emulate R rbind) +`Concatenate two dataframes with overlapping index (emulate R rbind) `__ .. ipython:: python @@ -944,7 +944,7 @@ Depending on df construction, ``ignore_index`` may be needed .. ipython:: python - df = df1.append(df2, ignore_index=True) + df = pd.concat([df1, df2], ignore_index=True) df `Self Join of a DataFrame diff --git a/doc/source/user_guide/merging.rst b/doc/source/user_guide/merging.rst index cee12c6939b25..bbca5773afdfe 100644 --- a/doc/source/user_guide/merging.rst +++ b/doc/source/user_guide/merging.rst @@ -237,59 +237,6 @@ Similarly, we could index before the concatenation: p.plot([df1, df4], result, labels=["df1", "df4"], vertical=False); plt.close("all"); -.. _merging.concatenation: - -Concatenating using ``append`` -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -A useful shortcut to :func:`~pandas.concat` are the :meth:`~DataFrame.append` -instance methods on ``Series`` and ``DataFrame``. These methods actually predated -``concat``. They concatenate along ``axis=0``, namely the index: - -.. ipython:: python - - result = df1.append(df2) - -.. ipython:: python - :suppress: - - @savefig merging_append1.png - p.plot([df1, df2], result, labels=["df1", "df2"], vertical=True); - plt.close("all"); - -In the case of ``DataFrame``, the indexes must be disjoint but the columns do not -need to be: - -.. ipython:: python - - result = df1.append(df4, sort=False) - -.. ipython:: python - :suppress: - - @savefig merging_append2.png - p.plot([df1, df4], result, labels=["df1", "df4"], vertical=True); - plt.close("all"); - -``append`` may take multiple objects to concatenate: - -.. ipython:: python - - result = df1.append([df2, df3]) - -.. ipython:: python - :suppress: - - @savefig merging_append3.png - p.plot([df1, df2, df3], result, labels=["df1", "df2", "df3"], vertical=True); - plt.close("all"); - -.. note:: - - Unlike the :py:meth:`~list.append` method, which appends to the original list - and returns ``None``, :meth:`~DataFrame.append` here **does not** modify - ``df1`` and returns its copy with ``df2`` appended. - .. _merging.ignore_index: Ignoring indexes on the concatenation axis @@ -309,19 +256,6 @@ do this, use the ``ignore_index`` argument: p.plot([df1, df4], result, labels=["df1", "df4"], vertical=True); plt.close("all"); -This is also a valid argument to :meth:`DataFrame.append`: - -.. ipython:: python - - result = df1.append(df4, ignore_index=True, sort=False) - -.. ipython:: python - :suppress: - - @savefig merging_append_ignore_index.png - p.plot([df1, df4], result, labels=["df1", "df4"], vertical=True); - plt.close("all"); - .. _merging.mixed_ndims: Concatenating with mixed ndims @@ -473,14 +407,13 @@ like GroupBy where the order of a categorical variable is meaningful. Appending rows to a DataFrame ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -While not especially efficient (since a new object must be created), you can -append a single row to a ``DataFrame`` by passing a ``Series`` or dict to -``append``, which returns a new ``DataFrame`` as above. +If you have a series that you want to append as a single row to a ``DataFrame``, you can convert the row into a +``DataFrame`` and use ``concat`` .. ipython:: python s2 = pd.Series(["X0", "X1", "X2", "X3"], index=["A", "B", "C", "D"]) - result = df1.append(s2, ignore_index=True) + result = pd.concat([df1, s2.to_frame().T], ignore_index=True) .. ipython:: python :suppress: @@ -493,20 +426,6 @@ You should use ``ignore_index`` with this method to instruct DataFrame to discard its index. If you wish to preserve the index, you should construct an appropriately-indexed DataFrame and append or concatenate those objects. -You can also pass a list of dicts or Series: - -.. ipython:: python - - dicts = [{"A": 1, "B": 2, "C": 3, "X": 4}, {"A": 5, "B": 6, "C": 7, "Y": 8}] - result = df1.append(dicts, ignore_index=True, sort=False) - -.. ipython:: python - :suppress: - - @savefig merging_append_dits.png - p.plot([df1, pd.DataFrame(dicts)], result, labels=["df1", "dicts"], vertical=True); - plt.close("all"); - .. _merging.join: Database-style DataFrame or named Series joining/merging diff --git a/doc/source/whatsnew/v0.6.1.rst b/doc/source/whatsnew/v0.6.1.rst index 139c6e2d1cb0c..4e72a630ad9f1 100644 --- a/doc/source/whatsnew/v0.6.1.rst +++ b/doc/source/whatsnew/v0.6.1.rst @@ -6,7 +6,7 @@ Version 0.6.1 (December 13, 2011) New features ~~~~~~~~~~~~ -- Can :ref:`append single rows ` (as Series) to a DataFrame +- Can append single rows (as Series) to a DataFrame - Add Spearman and Kendall rank :ref:`correlation ` options to Series.corr and DataFrame.corr (:issue:`428`) - :ref:`Added ` ``get_value`` and ``set_value`` methods to diff --git a/doc/source/whatsnew/v0.7.0.rst b/doc/source/whatsnew/v0.7.0.rst index 52747f2992dc4..1b947030ab8ab 100644 --- a/doc/source/whatsnew/v0.7.0.rst +++ b/doc/source/whatsnew/v0.7.0.rst @@ -19,7 +19,7 @@ New features intersection of the other axes. Improves performance of ``Series.append`` and ``DataFrame.append`` (:issue:`468`, :issue:`479`, :issue:`273`) -- :ref:`Can ` pass multiple DataFrames to +- Can pass multiple DataFrames to ``DataFrame.append`` to concatenate (stack) and multiple Series to ``Series.append`` too diff --git a/doc/source/whatsnew/v1.4.0.rst b/doc/source/whatsnew/v1.4.0.rst index 7218c77e43409..ef390756a20f6 100644 --- a/doc/source/whatsnew/v1.4.0.rst +++ b/doc/source/whatsnew/v1.4.0.rst @@ -275,7 +275,7 @@ ignored when finding the concatenated dtype. These are now consistently *not* i df1 = pd.DataFrame({"bar": [pd.Timestamp("2013-01-01")]}, index=range(1)) df2 = pd.DataFrame({"bar": np.nan}, index=range(1, 2)) - res = df1.append(df2) + res = pd.concat([df1, df2]) Previously, the float-dtype in ``df2`` would be ignored so the result dtype would be ``datetime64[ns]``. As a result, the ``np.nan`` would be cast to ``NaT``. @@ -510,6 +510,49 @@ when given numeric data, but in the future, a :class:`NumericIndex` will be retu Out [4]: NumericIndex([1, 2, 3], dtype='uint64') +.. _whatsnew_140.deprecations.frame_series_append: + +Deprecated Frame.append and Series.append +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +:meth:`DataFrame.append` and :meth:`Series.append` have been deprecated and will be removed in Pandas 2.0. +Use :func:`pandas.concat` instead (:issue:`35407`). + +*Deprecated syntax* + +.. code-block:: ipython + + In [1]: pd.Series([1, 2]).append(pd.Series([3, 4]) + Out [1]: + :1: FutureWarning: The series.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead. + 0 1 + 1 2 + 0 3 + 1 4 + dtype: int64 + + In [2]: df1 = pd.DataFrame([[1, 2], [3, 4]], columns=list('AB')) + In [3]: df2 = pd.DataFrame([[5, 6], [7, 8]], columns=list('AB')) + In [4]: df1.append(df2) + Out [4]: + :1: FutureWarning: The series.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead. + A B + 0 1 2 + 1 3 4 + 0 5 6 + 1 7 8 + +*Recommended syntax* + +.. ipython:: python + + pd.concat([pd.Series([1, 2]), pd.Series([3, 4])]) + + df1 = pd.DataFrame([[1, 2], [3, 4]], columns=list('AB')) + df2 = pd.DataFrame([[5, 6], [7, 8]], columns=list('AB')) + pd.concat([df1, df2]) + + .. _whatsnew_140.deprecations.other: Other Deprecations diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 794fb2afc7f9e..05fd20986da72 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -3261,9 +3261,10 @@ def memory_usage(self, index: bool = True, deep: bool = False) -> Series: index=self.columns, ) if index: - result = self._constructor_sliced( + index_memory_usage = self._constructor_sliced( self.index.memory_usage(deep=deep), index=["Index"] - ).append(result) + ) + result = index_memory_usage._append(result) return result def transpose(self, *args, copy: bool = False) -> DataFrame: @@ -9003,6 +9004,23 @@ def append( 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, + ignore_index: bool = False, + verify_integrity: bool = False, + sort: bool = False, + ) -> DataFrame: combined_columns = None if isinstance(other, (Series, dict)): if isinstance(other, dict): @@ -9728,7 +9746,9 @@ def c(x): idx_diff = result_index.difference(correl.index) if len(idx_diff) > 0: - correl = correl.append(Series([np.nan] * len(idx_diff), index=idx_diff)) + correl = correl._append( + Series([np.nan] * len(idx_diff), index=idx_diff) + ) return correl diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index f043a8cee308c..71ebb45cf23b4 100644 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -1993,7 +1993,7 @@ def _setitem_with_indexer_missing(self, indexer, value): df = df.infer_objects() self.obj._mgr = df._mgr else: - self.obj._mgr = self.obj.append(value)._mgr + self.obj._mgr = self.obj._append(value)._mgr self.obj._maybe_update_cacher(clear=True) def _ensure_iterable_column_indexer(self, column_indexer): diff --git a/pandas/core/reshape/pivot.py b/pandas/core/reshape/pivot.py index 8949ad3c8fca0..d40f8c69e1b7c 100644 --- a/pandas/core/reshape/pivot.py +++ b/pandas/core/reshape/pivot.py @@ -287,7 +287,7 @@ def _add_margins( if not values and isinstance(table, ABCSeries): # If there are no values and the table is a series, then there is only # one column in the data. Compute grand margin and return it. - return table.append(Series({key: grand_margin[margins_name]})) + return table._append(Series({key: grand_margin[margins_name]})) elif values: marginal_result_set = _generate_marginal_results( @@ -325,7 +325,7 @@ def _add_margins( margin_dummy[cols] = margin_dummy[cols].apply( maybe_downcast_to_dtype, args=(dtype,) ) - result = result.append(margin_dummy) + result = result._append(margin_dummy) result.index.names = row_names return result @@ -738,7 +738,7 @@ def _normalize(table, normalize, margins: bool, margins_name="All"): elif normalize == "index": index_margin = index_margin / index_margin.sum() - table = table.append(index_margin) + table = table._append(index_margin) table = table.fillna(0) table.index = table_index @@ -747,7 +747,7 @@ def _normalize(table, normalize, margins: bool, margins_name="All"): index_margin = index_margin / index_margin.sum() index_margin.loc[margins_name] = 1 table = concat([table, column_margin], axis=1) - table = table.append(index_margin) + table = table._append(index_margin) table = table.fillna(0) table.index = table_index diff --git a/pandas/core/series.py b/pandas/core/series.py index 746512e8fb7d6..da91dd243934f 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -2893,6 +2893,19 @@ def append( ... 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 + ): from pandas.core.reshape.concat import concat if isinstance(to_append, (list, tuple)): diff --git a/pandas/tests/frame/methods/test_append.py b/pandas/tests/frame/methods/test_append.py index c5b7a7ff69a53..5cfad472e0134 100644 --- a/pandas/tests/frame/methods/test_append.py +++ b/pandas/tests/frame/methods/test_append.py @@ -13,6 +13,7 @@ class TestDataFrameAppend: + @pytest.mark.filterwarnings("ignore:.*append method is deprecated.*:FutureWarning") def test_append_multiindex(self, multiindex_dataframe_random_data, frame_or_series): obj = multiindex_dataframe_random_data obj = tm.get_obj(obj, frame_or_series) @@ -26,16 +27,16 @@ def test_append_multiindex(self, multiindex_dataframe_random_data, frame_or_seri def test_append_empty_list(self): # GH 28769 df = DataFrame() - result = df.append([]) + result = df._append([]) expected = df tm.assert_frame_equal(result, expected) assert result is not df df = DataFrame(np.random.randn(5, 4), columns=["foo", "bar", "baz", "qux"]) - result = df.append([]) + result = df._append([]) expected = df tm.assert_frame_equal(result, expected) - assert result is not df # .append() should return a new object + assert result is not df # ._append() should return a new object def test_append_series_dict(self): df = DataFrame(np.random.randn(5, 4), columns=["foo", "bar", "baz", "qux"]) @@ -43,38 +44,38 @@ def test_append_series_dict(self): series = df.loc[4] msg = "Indexes have overlapping values" with pytest.raises(ValueError, match=msg): - df.append(series, verify_integrity=True) + df._append(series, verify_integrity=True) series.name = None msg = "Can only append a Series if ignore_index=True" with pytest.raises(TypeError, match=msg): - df.append(series, verify_integrity=True) + df._append(series, verify_integrity=True) - result = df.append(series[::-1], ignore_index=True) - expected = df.append( + result = df._append(series[::-1], ignore_index=True) + expected = df._append( DataFrame({0: series[::-1]}, index=df.columns).T, ignore_index=True ) tm.assert_frame_equal(result, expected) # dict - result = df.append(series.to_dict(), ignore_index=True) + result = df._append(series.to_dict(), ignore_index=True) tm.assert_frame_equal(result, expected) - result = df.append(series[::-1][:3], ignore_index=True) - expected = df.append( + result = df._append(series[::-1][:3], ignore_index=True) + expected = df._append( DataFrame({0: series[::-1][:3]}).T, ignore_index=True, sort=True ) tm.assert_frame_equal(result, expected.loc[:, result.columns]) msg = "Can only append a dict if ignore_index=True" with pytest.raises(TypeError, match=msg): - df.append(series.to_dict()) + df._append(series.to_dict()) # can append when name set row = df.loc[4] row.name = 5 - result = df.append(row) - expected = df.append(df[-1:], ignore_index=True) + result = df._append(row) + expected = df._append(df[-1:], ignore_index=True) tm.assert_frame_equal(result, expected) def test_append_list_of_series_dicts(self): @@ -82,8 +83,8 @@ def test_append_list_of_series_dicts(self): dicts = [x.to_dict() for idx, x in df.iterrows()] - result = df.append(dicts, ignore_index=True) - expected = df.append(df, ignore_index=True) + result = df._append(dicts, ignore_index=True) + expected = df._append(df, ignore_index=True) tm.assert_frame_equal(result, expected) # different columns @@ -91,8 +92,8 @@ def test_append_list_of_series_dicts(self): {"foo": 1, "bar": 2, "baz": 3, "peekaboo": 4}, {"foo": 5, "bar": 6, "baz": 7, "peekaboo": 8}, ] - result = df.append(dicts, ignore_index=True, sort=True) - expected = df.append(DataFrame(dicts), ignore_index=True, sort=True) + result = df._append(dicts, ignore_index=True, sort=True) + expected = df._append(DataFrame(dicts), ignore_index=True, sort=True) tm.assert_frame_equal(result, expected) def test_append_list_retain_index_name(self): @@ -108,11 +109,11 @@ def test_append_list_retain_index_name(self): ) # append series - result = df.append(serc) + result = df._append(serc) tm.assert_frame_equal(result, expected) # append list of series - result = df.append([serc]) + result = df._append([serc]) tm.assert_frame_equal(result, expected) def test_append_missing_cols(self): @@ -123,10 +124,9 @@ def test_append_missing_cols(self): df = DataFrame(np.random.randn(5, 4), columns=["foo", "bar", "baz", "qux"]) dicts = [{"foo": 9}, {"bar": 10}] - with tm.assert_produces_warning(None): - result = df.append(dicts, ignore_index=True, sort=True) + result = df._append(dicts, ignore_index=True, sort=True) - expected = df.append(DataFrame(dicts), ignore_index=True, sort=True) + expected = df._append(DataFrame(dicts), ignore_index=True, sort=True) tm.assert_frame_equal(result, expected) def test_append_empty_dataframe(self): @@ -134,28 +134,28 @@ def test_append_empty_dataframe(self): # Empty df append empty df df1 = DataFrame() df2 = DataFrame() - result = df1.append(df2) + result = df1._append(df2) expected = df1.copy() tm.assert_frame_equal(result, expected) # Non-empty df append empty df df1 = DataFrame(np.random.randn(5, 2)) df2 = DataFrame() - result = df1.append(df2) + result = df1._append(df2) expected = df1.copy() tm.assert_frame_equal(result, expected) # Empty df with columns append empty df df1 = DataFrame(columns=["bar", "foo"]) df2 = DataFrame() - result = df1.append(df2) + result = df1._append(df2) expected = df1.copy() tm.assert_frame_equal(result, expected) # Non-Empty df with columns append empty df df1 = DataFrame(np.random.randn(5, 2), columns=["bar", "foo"]) df2 = DataFrame() - result = df1.append(df2) + result = df1._append(df2) expected = df1.copy() tm.assert_frame_equal(result, expected) @@ -167,19 +167,19 @@ def test_append_dtypes(self): df1 = DataFrame({"bar": Timestamp("20130101")}, index=range(5)) df2 = DataFrame() - result = df1.append(df2) + result = df1._append(df2) expected = df1.copy() tm.assert_frame_equal(result, expected) df1 = DataFrame({"bar": Timestamp("20130101")}, index=range(1)) df2 = DataFrame({"bar": "foo"}, index=range(1, 2)) - result = df1.append(df2) + result = df1._append(df2) expected = DataFrame({"bar": [Timestamp("20130101"), "foo"]}) tm.assert_frame_equal(result, expected) df1 = DataFrame({"bar": Timestamp("20130101")}, index=range(1)) df2 = DataFrame({"bar": np.nan}, index=range(1, 2)) - result = df1.append(df2) + result = df1._append(df2) expected = DataFrame( {"bar": Series([Timestamp("20130101"), np.nan], dtype="M8[ns]")} ) @@ -188,7 +188,7 @@ def test_append_dtypes(self): df1 = DataFrame({"bar": Timestamp("20130101")}, index=range(1)) df2 = DataFrame({"bar": np.nan}, index=range(1, 2), dtype=object) - result = df1.append(df2) + result = df1._append(df2) expected = DataFrame( {"bar": Series([Timestamp("20130101"), np.nan], dtype="M8[ns]")} ) @@ -197,7 +197,7 @@ def test_append_dtypes(self): df1 = DataFrame({"bar": np.nan}, index=range(1)) df2 = DataFrame({"bar": Timestamp("20130101")}, index=range(1, 2)) - result = df1.append(df2) + result = df1._append(df2) expected = DataFrame( {"bar": Series([np.nan, Timestamp("20130101")], dtype="M8[ns]")} ) @@ -206,7 +206,7 @@ def test_append_dtypes(self): df1 = DataFrame({"bar": Timestamp("20130101")}, index=range(1)) df2 = DataFrame({"bar": 1}, index=range(1, 2), dtype=object) - result = df1.append(df2) + result = df1._append(df2) expected = DataFrame({"bar": Series([Timestamp("20130101"), 1])}) tm.assert_frame_equal(result, expected) @@ -217,7 +217,7 @@ def test_append_timestamps_aware_or_naive(self, tz_naive_fixture, timestamp): # GH 30238 tz = tz_naive_fixture df = DataFrame([Timestamp(timestamp, tz=tz)]) - result = df.append(df.iloc[0]).iloc[-1] + result = df._append(df.iloc[0]).iloc[-1] expected = Series(Timestamp(timestamp, tz=tz), name=0) tm.assert_series_equal(result, expected) @@ -233,7 +233,7 @@ def test_append_timestamps_aware_or_naive(self, tz_naive_fixture, timestamp): ) def test_other_dtypes(self, data, dtype): df = DataFrame(data, dtype=dtype) - result = df.append(df.iloc[0]).iloc[-1] + result = df._append(df.iloc[0]).iloc[-1] expected = Series(data, name=0, dtype=dtype) tm.assert_series_equal(result, expected) @@ -248,7 +248,7 @@ def test_append_numpy_bug_1681(self, dtype): df = DataFrame() other = DataFrame({"A": "foo", "B": index}, index=index) - result = df.append(other) + result = df._append(other) assert (result["B"] == index).all() @pytest.mark.filterwarnings("ignore:The values in the array:RuntimeWarning") @@ -263,9 +263,16 @@ def test_multiindex_column_append_multiple(self): df2 = df.copy() for i in range(1, 10): df[i, "colA"] = 10 - df = df.append(df2, ignore_index=True) + df = df._append(df2, ignore_index=True) result = df["multi"] expected = DataFrame( {"col1": [1, 2, 3] * (i + 1), "col2": [11, 12, 13] * (i + 1)} ) tm.assert_frame_equal(result, expected) + + def test_append_raises_future_warning(self): + # GH#35407 + df1 = DataFrame([[1, 2], [3, 4]]) + df2 = DataFrame([[5, 6], [7, 8]]) + with tm.assert_produces_warning(FutureWarning): + df1.append(df2) diff --git a/pandas/tests/frame/methods/test_drop_duplicates.py b/pandas/tests/frame/methods/test_drop_duplicates.py index 8cbf7bbfe0368..cd61f59a85d1e 100644 --- a/pandas/tests/frame/methods/test_drop_duplicates.py +++ b/pandas/tests/frame/methods/test_drop_duplicates.py @@ -7,6 +7,7 @@ from pandas import ( DataFrame, NaT, + concat, ) import pandas._testing as tm @@ -111,7 +112,7 @@ def test_drop_duplicates(): # GH 11864 df = DataFrame([i] * 9 for i in range(16)) - df = df.append([[1] + [0] * 8], ignore_index=True) + df = concat([df, DataFrame([[1] + [0] * 8])], ignore_index=True) for keep in ["first", "last", False]: assert df.duplicated(keep=keep).sum() == 0 diff --git a/pandas/tests/generic/test_duplicate_labels.py b/pandas/tests/generic/test_duplicate_labels.py index 1b32675ec2d35..1c0ae46aa5500 100644 --- a/pandas/tests/generic/test_duplicate_labels.py +++ b/pandas/tests/generic/test_duplicate_labels.py @@ -294,14 +294,12 @@ def test_setting_allows_duplicate_labels_raises(self, data): assert data.flags.allows_duplicate_labels is True - @pytest.mark.parametrize( - "func", [operator.methodcaller("append", pd.Series(0, index=["a", "b"]))] - ) - def test_series_raises(self, func): - s = pd.Series([0, 1], index=["a", "b"]).set_flags(allows_duplicate_labels=False) + def test_series_raises(self): + a = pd.Series(0, index=["a", "b"]) + b = pd.Series([0, 1], index=["a", "b"]).set_flags(allows_duplicate_labels=False) msg = "Index has duplicates." with pytest.raises(pd.errors.DuplicateLabelError, match=msg): - func(s) + pd.concat([a, b]) @pytest.mark.parametrize( "getter, target", diff --git a/pandas/tests/generic/test_finalize.py b/pandas/tests/generic/test_finalize.py index f27e92a55268f..ba9cb22ed27a5 100644 --- a/pandas/tests/generic/test_finalize.py +++ b/pandas/tests/generic/test_finalize.py @@ -180,7 +180,10 @@ pd.DataFrame, frame_data, operator.methodcaller("append", pd.DataFrame({"A": [1]})), - ) + ), + marks=pytest.mark.filterwarnings( + "ignore:.*append method is deprecated.*:FutureWarning" + ), ), pytest.param( ( @@ -188,6 +191,9 @@ frame_data, operator.methodcaller("append", pd.DataFrame({"B": [1]})), ), + marks=pytest.mark.filterwarnings( + "ignore:.*append method is deprecated.*:FutureWarning" + ), ), pytest.param( ( diff --git a/pandas/tests/indexes/period/test_indexing.py b/pandas/tests/indexes/period/test_indexing.py index e193af062098b..df40822337ed0 100644 --- a/pandas/tests/indexes/period/test_indexing.py +++ b/pandas/tests/indexes/period/test_indexing.py @@ -144,7 +144,7 @@ def test_getitem_partial(self): result = ts[24:] tm.assert_series_equal(exp, result) - ts = ts[10:].append(ts[10:]) + ts = pd.concat([ts[10:], ts[10:]]) msg = "left slice bound for non-unique label: '2008'" with pytest.raises(KeyError, match=msg): ts[slice("2008", "2009")] diff --git a/pandas/tests/indexing/test_partial.py b/pandas/tests/indexing/test_partial.py index 95a9fd227c685..8251f09b97062 100644 --- a/pandas/tests/indexing/test_partial.py +++ b/pandas/tests/indexing/test_partial.py @@ -361,7 +361,7 @@ def test_partial_setting_mixed_dtype(self): s = df.loc[1].copy() s.name = 2 - expected = df.append(s) + expected = pd.concat([df, DataFrame(s).T.infer_objects()]) df.loc[2] = df.loc[1] tm.assert_frame_equal(df, expected) @@ -538,7 +538,8 @@ def test_partial_set_invalid(self): # allow object conversion here df = orig.copy() df.loc["a", :] = df.iloc[0] - exp = orig.append(Series(df.iloc[0], name="a")) + ser = Series(df.iloc[0], name="a") + exp = pd.concat([orig, DataFrame(ser).T.infer_objects()]) tm.assert_frame_equal(df, exp) tm.assert_index_equal(df.index, Index(orig.index.tolist() + ["a"])) assert df.index.dtype == "object" diff --git a/pandas/tests/io/formats/test_format.py b/pandas/tests/io/formats/test_format.py index ab0199dca3f24..fe6914e6ef4f5 100644 --- a/pandas/tests/io/formats/test_format.py +++ b/pandas/tests/io/formats/test_format.py @@ -2427,7 +2427,7 @@ def test_datetimeindex(self): # nat in index s2 = Series(2, index=[Timestamp("20130111"), NaT]) - s = s2.append(s) + s = pd.concat([s2, s]) result = s.to_string() assert "NaT" in result diff --git a/pandas/tests/resample/test_time_grouper.py b/pandas/tests/resample/test_time_grouper.py index 4f69a7f590319..2e512d74076d3 100644 --- a/pandas/tests/resample/test_time_grouper.py +++ b/pandas/tests/resample/test_time_grouper.py @@ -207,7 +207,7 @@ def test_aggregate_with_nat(func, fill_value): dt_result = getattr(dt_grouped, func)() pad = DataFrame([[fill_value] * 4], index=[3], columns=["A", "B", "C", "D"]) - expected = normal_result.append(pad) + expected = pd.concat([normal_result, pad]) expected = expected.sort_index() dti = date_range(start="2013-01-01", freq="D", periods=5, name="key") expected.index = dti._with_freq(None) # TODO: is this desired? @@ -238,7 +238,7 @@ def test_aggregate_with_nat_size(): dt_result = dt_grouped.size() pad = Series([0], index=[3]) - expected = normal_result.append(pad) + expected = pd.concat([normal_result, pad]) expected = expected.sort_index() expected.index = date_range( start="2013-01-01", freq="D", periods=5, name="key" diff --git a/pandas/tests/reshape/concat/test_append.py b/pandas/tests/reshape/concat/test_append.py index 061afb3a7e0f5..0b1d1c4a3d346 100644 --- a/pandas/tests/reshape/concat/test_append.py +++ b/pandas/tests/reshape/concat/test_append.py @@ -28,23 +28,23 @@ def test_append(self, sort, float_frame): begin_frame = float_frame.reindex(begin_index) end_frame = float_frame.reindex(end_index) - appended = begin_frame.append(end_frame) + appended = begin_frame._append(end_frame) tm.assert_almost_equal(appended["A"], float_frame["A"]) del end_frame["A"] - partial_appended = begin_frame.append(end_frame, sort=sort) + partial_appended = begin_frame._append(end_frame, sort=sort) assert "A" in partial_appended - partial_appended = end_frame.append(begin_frame, sort=sort) + partial_appended = end_frame._append(begin_frame, sort=sort) assert "A" in partial_appended # mixed type handling - appended = mixed_frame[:5].append(mixed_frame[5:]) + appended = mixed_frame[:5]._append(mixed_frame[5:]) tm.assert_frame_equal(appended, mixed_frame) # what to test here - mixed_appended = mixed_frame[:5].append(float_frame[5:], sort=sort) - mixed_appended2 = float_frame[:5].append(mixed_frame[5:], sort=sort) + mixed_appended = mixed_frame[:5]._append(float_frame[5:], sort=sort) + mixed_appended2 = float_frame[:5]._append(mixed_frame[5:], sort=sort) # all equal except 'foo' column tm.assert_frame_equal( @@ -55,18 +55,18 @@ def test_append(self, sort, float_frame): def test_append_empty(self, float_frame): empty = DataFrame() - appended = float_frame.append(empty) + appended = float_frame._append(empty) tm.assert_frame_equal(float_frame, appended) assert appended is not float_frame - appended = empty.append(float_frame) + appended = empty._append(float_frame) tm.assert_frame_equal(float_frame, appended) assert appended is not float_frame def test_append_overlap_raises(self, float_frame): msg = "Indexes have overlapping values" with pytest.raises(ValueError, match=msg): - float_frame.append(float_frame, verify_integrity=True) + float_frame._append(float_frame, verify_integrity=True) def test_append_new_columns(self): # see gh-6129: new columns @@ -79,13 +79,13 @@ def test_append_new_columns(self): "c": {"z": 7}, } ) - result = df.append(row) + result = df._append(row) tm.assert_frame_equal(result, expected) def test_append_length0_frame(self, sort): df = DataFrame(columns=["A", "B", "C"]) df3 = DataFrame(index=[0, 1], columns=["A", "B"]) - df5 = df.append(df3, sort=sort) + df5 = df._append(df3, sort=sort) expected = DataFrame(index=[0, 1], columns=["A", "B", "C"]) tm.assert_frame_equal(df5, expected) @@ -100,7 +100,7 @@ def test_append_records(self): df1 = DataFrame(arr1) df2 = DataFrame(arr2) - result = df1.append(df2, ignore_index=True) + result = df1._append(df2, ignore_index=True) expected = DataFrame(np.concatenate((arr1, arr2))) tm.assert_frame_equal(result, expected) @@ -109,8 +109,7 @@ def test_append_sorts(self, sort): df1 = DataFrame({"a": [1, 2], "b": [1, 2]}, columns=["b", "a"]) df2 = DataFrame({"a": [1, 2], "c": [3, 4]}, index=[2, 3]) - with tm.assert_produces_warning(None): - result = df1.append(df2, sort=sort) + result = df1._append(df2, sort=sort) # for None / True expected = DataFrame( @@ -134,7 +133,7 @@ def test_append_different_columns(self, sort): a = df[:5].loc[:, ["bools", "ints", "floats"]] b = df[5:].loc[:, ["strings", "ints", "floats"]] - appended = a.append(b, sort=sort) + appended = a._append(b, sort=sort) assert isna(appended["strings"][0:4]).all() assert isna(appended["bools"][5:]).all() @@ -146,12 +145,12 @@ def test_append_many(self, sort, float_frame): float_frame[15:], ] - result = chunks[0].append(chunks[1:]) + result = chunks[0]._append(chunks[1:]) tm.assert_frame_equal(result, float_frame) chunks[-1] = chunks[-1].copy() chunks[-1]["foo"] = "bar" - result = chunks[0].append(chunks[1:], sort=sort) + result = chunks[0]._append(chunks[1:], sort=sort) tm.assert_frame_equal(result.loc[:, float_frame.columns], float_frame) assert (result["foo"][15:] == "bar").all() assert result["foo"][:15].isna().all() @@ -163,7 +162,7 @@ def test_append_preserve_index_name(self): df2 = DataFrame(data=[[1, 4, 7], [2, 5, 8], [3, 6, 9]], columns=["A", "B", "C"]) df2 = df2.set_index(["A"]) - result = df1.append(df2) + result = df1._append(df2) assert result.index.name == "A" indexes_can_append = [ @@ -194,7 +193,7 @@ def test_append_same_columns_type(self, index): df = DataFrame([[1, 2, 3], [4, 5, 6]], columns=index) ser_index = index[:2] ser = Series([7, 8], index=ser_index, name=2) - result = df.append(ser) + result = df._append(ser) expected = DataFrame( [[1, 2, 3.0], [4, 5, 6], [7, 8, np.nan]], index=[0, 1, 2], columns=index ) @@ -209,7 +208,7 @@ def test_append_same_columns_type(self, index): index = index[:2] df = DataFrame([[1, 2], [4, 5]], columns=index) ser = Series([7, 8, 9], index=ser_index, name=2) - result = df.append(ser) + result = df._append(ser) expected = DataFrame( [[1, 2, np.nan], [4, 5, np.nan], [7, 8, 9]], index=[0, 1, 2], @@ -230,7 +229,7 @@ def test_append_different_columns_types(self, df_columns, series_index): df = DataFrame([[1, 2, 3], [4, 5, 6]], columns=df_columns) ser = Series([7, 8, 9], index=series_index, name=2) - result = df.append(ser) + result = df._append(ser) idx_diff = ser.index.difference(df_columns) combined_columns = Index(df_columns.tolist()).append(idx_diff) expected = DataFrame( @@ -287,7 +286,7 @@ def test_append_dtype_coerce(self, sort): axis=1, sort=sort, ) - result = df1.append(df2, ignore_index=True, sort=sort) + result = df1._append(df2, ignore_index=True, sort=sort) if sort: expected = expected[["end_time", "start_time"]] else: @@ -299,7 +298,7 @@ def test_append_missing_column_proper_upcast(self, sort): df1 = DataFrame({"A": np.array([1, 2, 3, 4], dtype="i8")}) df2 = DataFrame({"B": np.array([True, False, True, False], dtype=bool)}) - appended = df1.append(df2, ignore_index=True, sort=sort) + appended = df1._append(df2, ignore_index=True, sort=sort) assert appended["A"].dtype == "f8" assert appended["B"].dtype == "O" @@ -308,7 +307,7 @@ def test_append_empty_frame_to_series_with_dateutil_tz(self): date = Timestamp("2018-10-24 07:30:00", tz=dateutil.tz.tzutc()) ser = Series({"a": 1.0, "b": 2.0, "date": date}) df = DataFrame(columns=["c", "d"]) - result_a = df.append(ser, ignore_index=True) + result_a = df._append(ser, ignore_index=True) expected = DataFrame( [[np.nan, np.nan, 1.0, 2.0, date]], columns=["c", "d", "a", "b", "date"] ) @@ -322,10 +321,10 @@ def test_append_empty_frame_to_series_with_dateutil_tz(self): ) expected["c"] = expected["c"].astype(object) expected["d"] = expected["d"].astype(object) - result_b = result_a.append(ser, ignore_index=True) + result_b = result_a._append(ser, ignore_index=True) tm.assert_frame_equal(result_b, expected) - result = df.append([ser, ser], ignore_index=True) + result = df._append([ser, ser], ignore_index=True) tm.assert_frame_equal(result, expected) def test_append_empty_tz_frame_with_datetime64ns(self): @@ -333,20 +332,20 @@ def test_append_empty_tz_frame_with_datetime64ns(self): df = DataFrame(columns=["a"]).astype("datetime64[ns, UTC]") # pd.NaT gets inferred as tz-naive, so append result is tz-naive - result = df.append({"a": pd.NaT}, ignore_index=True) + result = df._append({"a": pd.NaT}, ignore_index=True) expected = DataFrame({"a": [pd.NaT]}).astype(object) tm.assert_frame_equal(result, expected) # also test with typed value to append df = DataFrame(columns=["a"]).astype("datetime64[ns, UTC]") other = Series({"a": pd.NaT}, dtype="datetime64[ns]") - result = df.append(other, ignore_index=True) + result = df._append(other, ignore_index=True) expected = DataFrame({"a": [pd.NaT]}).astype(object) tm.assert_frame_equal(result, expected) # mismatched tz other = Series({"a": pd.NaT}, dtype="datetime64[ns, US/Pacific]") - result = df.append(other, ignore_index=True) + result = df._append(other, ignore_index=True) expected = DataFrame({"a": [pd.NaT]}).astype(object) tm.assert_frame_equal(result, expected) @@ -359,7 +358,7 @@ def test_append_empty_frame_with_timedelta64ns_nat(self, dtype_str, val): df = DataFrame(columns=["a"]).astype(dtype_str) other = DataFrame({"a": [np.timedelta64(val, "ns")]}) - result = df.append(other, ignore_index=True) + result = df._append(other, ignore_index=True) expected = other.astype(object) tm.assert_frame_equal(result, expected) @@ -373,7 +372,7 @@ def test_append_frame_with_timedelta64ns_nat(self, dtype_str, val): df = DataFrame({"a": pd.array([1], dtype=dtype_str)}) other = DataFrame({"a": [np.timedelta64(val, "ns")]}) - result = df.append(other, ignore_index=True) + result = df._append(other, ignore_index=True) expected = DataFrame({"a": [df.iloc[0, 0], other.iloc[0, 0]]}, dtype=object) tm.assert_frame_equal(result, expected) diff --git a/pandas/tests/reshape/concat/test_append_common.py b/pandas/tests/reshape/concat/test_append_common.py index d5d86465dd91b..bb8027948c540 100644 --- a/pandas/tests/reshape/concat/test_append_common.py +++ b/pandas/tests/reshape/concat/test_append_common.py @@ -129,7 +129,7 @@ def test_concatlike_same_dtypes(self, item): # ----- Series ----- # # series.append - res = Series(vals1).append(Series(vals2), ignore_index=True) + res = Series(vals1)._append(Series(vals2), ignore_index=True) exp = Series(exp_data) tm.assert_series_equal(res, exp, check_index_type=True) @@ -138,7 +138,7 @@ def test_concatlike_same_dtypes(self, item): tm.assert_series_equal(res, exp, check_index_type=True) # 3 elements - res = Series(vals1).append([Series(vals2), Series(vals3)], ignore_index=True) + res = Series(vals1)._append([Series(vals2), Series(vals3)], ignore_index=True) exp = Series(exp_data3) tm.assert_series_equal(res, exp) @@ -151,7 +151,7 @@ def test_concatlike_same_dtypes(self, item): # name mismatch s1 = Series(vals1, name="x") s2 = Series(vals2, name="y") - res = s1.append(s2, ignore_index=True) + res = s1._append(s2, ignore_index=True) exp = Series(exp_data) tm.assert_series_equal(res, exp, check_index_type=True) @@ -161,7 +161,7 @@ def test_concatlike_same_dtypes(self, item): # name match s1 = Series(vals1, name="x") s2 = Series(vals2, name="x") - res = s1.append(s2, ignore_index=True) + res = s1._append(s2, ignore_index=True) exp = Series(exp_data, name="x") tm.assert_series_equal(res, exp, check_index_type=True) @@ -174,10 +174,10 @@ def test_concatlike_same_dtypes(self, item): "only Series and DataFrame objs are valid" ) with pytest.raises(TypeError, match=msg): - Series(vals1).append(vals2) + Series(vals1)._append(vals2) with pytest.raises(TypeError, match=msg): - Series(vals1).append([Series(vals2), vals3]) + Series(vals1)._append([Series(vals2), vals3]) with pytest.raises(TypeError, match=msg): pd.concat([Series(vals1), vals2]) @@ -237,8 +237,8 @@ def test_concatlike_dtypes_coercion(self, item, item2): # ----- Series ----- # - # series.append - res = Series(vals1).append(Series(vals2), ignore_index=True) + # series._append + res = Series(vals1)._append(Series(vals2), ignore_index=True) exp = Series(exp_data, dtype=exp_series_dtype) tm.assert_series_equal(res, exp, check_index_type=True) @@ -247,7 +247,7 @@ def test_concatlike_dtypes_coercion(self, item, item2): tm.assert_series_equal(res, exp, check_index_type=True) # 3 elements - res = Series(vals1).append([Series(vals2), Series(vals3)], ignore_index=True) + res = Series(vals1)._append([Series(vals2), Series(vals3)], ignore_index=True) exp = Series(exp_data3, dtype=exp_series_dtype) tm.assert_series_equal(res, exp) @@ -279,7 +279,7 @@ def test_concatlike_common_coerce_to_pandas_object(self): dts = Series(dti) tds = Series(tdi) - res = dts.append(tds) + res = dts._append(tds) tm.assert_series_equal(res, Series(exp, index=[0, 1, 0, 1])) assert isinstance(res.iloc[0], pd.Timestamp) assert isinstance(res.iloc[-1], pd.Timedelta) @@ -304,7 +304,7 @@ def test_concatlike_datetimetz(self, tz_aware_fixture): dts1 = Series(dti1) dts2 = Series(dti2) - res = dts1.append(dts2) + res = dts1._append(dts2) tm.assert_series_equal(res, Series(exp, index=[0, 1, 0, 1])) res = pd.concat([dts1, dts2]) @@ -324,7 +324,7 @@ def test_concatlike_datetimetz_short(self, tz): ) exp = DataFrame(0, index=exp_idx, columns=["A", "B"]) - tm.assert_frame_equal(df1.append(df2), exp) + tm.assert_frame_equal(df1._append(df2), exp) tm.assert_frame_equal(pd.concat([df1, df2]), exp) def test_concatlike_datetimetz_to_object(self, tz_aware_fixture): @@ -350,7 +350,7 @@ def test_concatlike_datetimetz_to_object(self, tz_aware_fixture): dts1 = Series(dti1) dts2 = Series(dti2) - res = dts1.append(dts2) + res = dts1._append(dts2) tm.assert_series_equal(res, Series(exp, index=[0, 1, 0, 1])) res = pd.concat([dts1, dts2]) @@ -374,7 +374,7 @@ def test_concatlike_datetimetz_to_object(self, tz_aware_fixture): dts1 = Series(dti1) dts3 = Series(dti3) - res = dts1.append(dts3) + res = dts1._append(dts3) tm.assert_series_equal(res, Series(exp, index=[0, 1, 0, 1])) res = pd.concat([dts1, dts3]) @@ -392,7 +392,7 @@ def test_concatlike_common_period(self): ps1 = Series(pi1) ps2 = Series(pi2) - res = ps1.append(ps2) + res = ps1._append(ps2) tm.assert_series_equal(res, Series(exp, index=[0, 1, 0, 1])) res = pd.concat([ps1, ps2]) @@ -418,7 +418,7 @@ def test_concatlike_common_period_diff_freq_to_object(self): ps1 = Series(pi1) ps2 = Series(pi2) - res = ps1.append(ps2) + res = ps1._append(ps2) tm.assert_series_equal(res, Series(exp, index=[0, 1, 0, 1])) res = pd.concat([ps1, ps2]) @@ -444,7 +444,7 @@ def test_concatlike_common_period_mixed_dt_to_object(self): ps1 = Series(pi1) tds = Series(tdi) - res = ps1.append(tds) + res = ps1._append(tds) tm.assert_series_equal(res, Series(exp, index=[0, 1, 0, 1])) res = pd.concat([ps1, tds]) @@ -466,7 +466,7 @@ def test_concatlike_common_period_mixed_dt_to_object(self): ps1 = Series(pi1) tds = Series(tdi) - res = tds.append(ps1) + res = tds._append(ps1) tm.assert_series_equal(res, Series(exp, index=[0, 1, 0, 1])) res = pd.concat([tds, ps1]) @@ -481,7 +481,7 @@ def test_concat_categorical(self): exp = Series([1, 2, np.nan, 2, 1, 2], dtype="category") tm.assert_series_equal(pd.concat([s1, s2], ignore_index=True), exp) - tm.assert_series_equal(s1.append(s2, ignore_index=True), exp) + tm.assert_series_equal(s1._append(s2, ignore_index=True), exp) # partially different categories => not-category s1 = Series([3, 2], dtype="category") @@ -489,7 +489,7 @@ def test_concat_categorical(self): exp = Series([3, 2, 2, 1]) tm.assert_series_equal(pd.concat([s1, s2], ignore_index=True), exp) - tm.assert_series_equal(s1.append(s2, ignore_index=True), exp) + tm.assert_series_equal(s1._append(s2, ignore_index=True), exp) # completely different categories (same dtype) => not-category s1 = Series([10, 11, np.nan], dtype="category") @@ -497,7 +497,7 @@ def test_concat_categorical(self): exp = Series([10, 11, np.nan, np.nan, 1, 3, 2], dtype="object") tm.assert_series_equal(pd.concat([s1, s2], ignore_index=True), exp) - tm.assert_series_equal(s1.append(s2, ignore_index=True), exp) + tm.assert_series_equal(s1._append(s2, ignore_index=True), exp) def test_union_categorical_same_categories_different_order(self): # https://github.com/pandas-dev/pandas/issues/19096 @@ -518,12 +518,12 @@ def test_concat_categorical_coercion(self): exp = Series([1, 2, np.nan, 2, 1, 2], dtype="object") tm.assert_series_equal(pd.concat([s1, s2], ignore_index=True), exp) - tm.assert_series_equal(s1.append(s2, ignore_index=True), exp) + tm.assert_series_equal(s1._append(s2, ignore_index=True), exp) # result shouldn't be affected by 1st elem dtype exp = Series([2, 1, 2, 1, 2, np.nan], dtype="object") tm.assert_series_equal(pd.concat([s2, s1], ignore_index=True), exp) - tm.assert_series_equal(s2.append(s1, ignore_index=True), exp) + tm.assert_series_equal(s2._append(s1, ignore_index=True), exp) # all values are not in category => not-category s1 = Series([3, 2], dtype="category") @@ -531,11 +531,11 @@ def test_concat_categorical_coercion(self): exp = Series([3, 2, 2, 1]) tm.assert_series_equal(pd.concat([s1, s2], ignore_index=True), exp) - tm.assert_series_equal(s1.append(s2, ignore_index=True), exp) + tm.assert_series_equal(s1._append(s2, ignore_index=True), exp) exp = Series([2, 1, 3, 2]) tm.assert_series_equal(pd.concat([s2, s1], ignore_index=True), exp) - tm.assert_series_equal(s2.append(s1, ignore_index=True), exp) + tm.assert_series_equal(s2._append(s1, ignore_index=True), exp) # completely different categories => not-category s1 = Series([10, 11, np.nan], dtype="category") @@ -543,11 +543,11 @@ def test_concat_categorical_coercion(self): exp = Series([10, 11, np.nan, 1, 3, 2], dtype="object") tm.assert_series_equal(pd.concat([s1, s2], ignore_index=True), exp) - tm.assert_series_equal(s1.append(s2, ignore_index=True), exp) + tm.assert_series_equal(s1._append(s2, ignore_index=True), exp) exp = Series([1, 3, 2, 10, 11, np.nan], dtype="object") tm.assert_series_equal(pd.concat([s2, s1], ignore_index=True), exp) - tm.assert_series_equal(s2.append(s1, ignore_index=True), exp) + tm.assert_series_equal(s2._append(s1, ignore_index=True), exp) # different dtype => not-category s1 = Series([10, 11, np.nan], dtype="category") @@ -555,11 +555,11 @@ def test_concat_categorical_coercion(self): exp = Series([10, 11, np.nan, "a", "b", "c"]) tm.assert_series_equal(pd.concat([s1, s2], ignore_index=True), exp) - tm.assert_series_equal(s1.append(s2, ignore_index=True), exp) + tm.assert_series_equal(s1._append(s2, ignore_index=True), exp) exp = Series(["a", "b", "c", 10, 11, np.nan]) tm.assert_series_equal(pd.concat([s2, s1], ignore_index=True), exp) - tm.assert_series_equal(s2.append(s1, ignore_index=True), exp) + tm.assert_series_equal(s2._append(s1, ignore_index=True), exp) # if normal series only contains NaN-likes => not-category s1 = Series([10, 11], dtype="category") @@ -567,11 +567,11 @@ def test_concat_categorical_coercion(self): exp = Series([10, 11, np.nan, np.nan, np.nan]) tm.assert_series_equal(pd.concat([s1, s2], ignore_index=True), exp) - tm.assert_series_equal(s1.append(s2, ignore_index=True), exp) + tm.assert_series_equal(s1._append(s2, ignore_index=True), exp) exp = Series([np.nan, np.nan, np.nan, 10, 11]) tm.assert_series_equal(pd.concat([s2, s1], ignore_index=True), exp) - tm.assert_series_equal(s2.append(s1, ignore_index=True), exp) + tm.assert_series_equal(s2._append(s1, ignore_index=True), exp) def test_concat_categorical_3elem_coercion(self): # GH 13524 @@ -583,11 +583,11 @@ def test_concat_categorical_3elem_coercion(self): exp = Series([1, 2, np.nan, 2, 1, 2, 1, 2, 1, 2, np.nan], dtype="float") tm.assert_series_equal(pd.concat([s1, s2, s3], ignore_index=True), exp) - tm.assert_series_equal(s1.append([s2, s3], ignore_index=True), exp) + tm.assert_series_equal(s1._append([s2, s3], ignore_index=True), exp) exp = Series([1, 2, 1, 2, np.nan, 1, 2, np.nan, 2, 1, 2], dtype="float") tm.assert_series_equal(pd.concat([s3, s1, s2], ignore_index=True), exp) - tm.assert_series_equal(s3.append([s1, s2], ignore_index=True), exp) + tm.assert_series_equal(s3._append([s1, s2], ignore_index=True), exp) # values are all in either category => not-category s1 = Series([4, 5, 6], dtype="category") @@ -596,11 +596,11 @@ def test_concat_categorical_3elem_coercion(self): exp = Series([4, 5, 6, 1, 2, 3, 1, 3, 4]) tm.assert_series_equal(pd.concat([s1, s2, s3], ignore_index=True), exp) - tm.assert_series_equal(s1.append([s2, s3], ignore_index=True), exp) + tm.assert_series_equal(s1._append([s2, s3], ignore_index=True), exp) exp = Series([1, 3, 4, 4, 5, 6, 1, 2, 3]) tm.assert_series_equal(pd.concat([s3, s1, s2], ignore_index=True), exp) - tm.assert_series_equal(s3.append([s1, s2], ignore_index=True), exp) + tm.assert_series_equal(s3._append([s1, s2], ignore_index=True), exp) # values are all in either category => not-category s1 = Series([4, 5, 6], dtype="category") @@ -609,11 +609,11 @@ def test_concat_categorical_3elem_coercion(self): exp = Series([4, 5, 6, 1, 2, 3, 10, 11, 12]) tm.assert_series_equal(pd.concat([s1, s2, s3], ignore_index=True), exp) - tm.assert_series_equal(s1.append([s2, s3], ignore_index=True), exp) + tm.assert_series_equal(s1._append([s2, s3], ignore_index=True), exp) exp = Series([10, 11, 12, 4, 5, 6, 1, 2, 3]) tm.assert_series_equal(pd.concat([s3, s1, s2], ignore_index=True), exp) - tm.assert_series_equal(s3.append([s1, s2], ignore_index=True), exp) + tm.assert_series_equal(s3._append([s1, s2], ignore_index=True), exp) def test_concat_categorical_multi_coercion(self): # GH 13524 @@ -629,13 +629,13 @@ def test_concat_categorical_multi_coercion(self): exp = Series([1, 3, 3, 4, 2, 3, 2, 2, 1, np.nan, 1, 3, 2]) res = pd.concat([s1, s2, s3, s4, s5, s6], ignore_index=True) tm.assert_series_equal(res, exp) - res = s1.append([s2, s3, s4, s5, s6], ignore_index=True) + res = s1._append([s2, s3, s4, s5, s6], ignore_index=True) tm.assert_series_equal(res, exp) exp = Series([1, 3, 2, 1, np.nan, 2, 2, 2, 3, 3, 4, 1, 3]) res = pd.concat([s6, s5, s4, s3, s2, s1], ignore_index=True) tm.assert_series_equal(res, exp) - res = s6.append([s5, s4, s3, s2, s1], ignore_index=True) + res = s6._append([s5, s4, s3, s2, s1], ignore_index=True) tm.assert_series_equal(res, exp) def test_concat_categorical_ordered(self): @@ -646,11 +646,11 @@ def test_concat_categorical_ordered(self): exp = Series(Categorical([1, 2, np.nan, 2, 1, 2], ordered=True)) tm.assert_series_equal(pd.concat([s1, s2], ignore_index=True), exp) - tm.assert_series_equal(s1.append(s2, ignore_index=True), exp) + tm.assert_series_equal(s1._append(s2, ignore_index=True), exp) exp = Series(Categorical([1, 2, np.nan, 2, 1, 2, 1, 2, np.nan], ordered=True)) tm.assert_series_equal(pd.concat([s1, s2, s1], ignore_index=True), exp) - tm.assert_series_equal(s1.append([s2, s1], ignore_index=True), exp) + tm.assert_series_equal(s1._append([s2, s1], ignore_index=True), exp) def test_concat_categorical_coercion_nan(self): # GH 13524 @@ -662,14 +662,14 @@ def test_concat_categorical_coercion_nan(self): exp = Series([np.nan, np.nan, np.nan, 1]) tm.assert_series_equal(pd.concat([s1, s2], ignore_index=True), exp) - tm.assert_series_equal(s1.append(s2, ignore_index=True), exp) + tm.assert_series_equal(s1._append(s2, ignore_index=True), exp) s1 = Series([1, np.nan], dtype="category") s2 = Series([np.nan, np.nan]) exp = Series([1, np.nan, np.nan, np.nan], dtype="float") tm.assert_series_equal(pd.concat([s1, s2], ignore_index=True), exp) - tm.assert_series_equal(s1.append(s2, ignore_index=True), exp) + tm.assert_series_equal(s1._append(s2, ignore_index=True), exp) # mixed dtype, all nan-likes => not-category s1 = Series([np.nan, np.nan], dtype="category") @@ -677,9 +677,9 @@ def test_concat_categorical_coercion_nan(self): exp = Series([np.nan, np.nan, np.nan, np.nan]) tm.assert_series_equal(pd.concat([s1, s2], ignore_index=True), exp) - tm.assert_series_equal(s1.append(s2, ignore_index=True), exp) + tm.assert_series_equal(s1._append(s2, ignore_index=True), exp) tm.assert_series_equal(pd.concat([s2, s1], ignore_index=True), exp) - tm.assert_series_equal(s2.append(s1, ignore_index=True), exp) + tm.assert_series_equal(s2._append(s1, ignore_index=True), exp) # all category nan-likes => category s1 = Series([np.nan, np.nan], dtype="category") @@ -688,7 +688,7 @@ def test_concat_categorical_coercion_nan(self): exp = Series([np.nan, np.nan, np.nan, np.nan], dtype="category") tm.assert_series_equal(pd.concat([s1, s2], ignore_index=True), exp) - tm.assert_series_equal(s1.append(s2, ignore_index=True), exp) + tm.assert_series_equal(s1._append(s2, ignore_index=True), exp) def test_concat_categorical_empty(self): # GH 13524 @@ -697,25 +697,25 @@ def test_concat_categorical_empty(self): s2 = Series([1, 2], dtype="category") tm.assert_series_equal(pd.concat([s1, s2], ignore_index=True), s2) - tm.assert_series_equal(s1.append(s2, ignore_index=True), s2) + tm.assert_series_equal(s1._append(s2, ignore_index=True), s2) tm.assert_series_equal(pd.concat([s2, s1], ignore_index=True), s2) - tm.assert_series_equal(s2.append(s1, ignore_index=True), s2) + tm.assert_series_equal(s2._append(s1, ignore_index=True), s2) s1 = Series([], dtype="category") s2 = Series([], dtype="category") tm.assert_series_equal(pd.concat([s1, s2], ignore_index=True), s2) - tm.assert_series_equal(s1.append(s2, ignore_index=True), s2) + tm.assert_series_equal(s1._append(s2, ignore_index=True), s2) s1 = Series([], dtype="category") s2 = Series([], dtype="object") # different dtype => not-category tm.assert_series_equal(pd.concat([s1, s2], ignore_index=True), s2) - tm.assert_series_equal(s1.append(s2, ignore_index=True), s2) + tm.assert_series_equal(s1._append(s2, ignore_index=True), s2) tm.assert_series_equal(pd.concat([s2, s1], ignore_index=True), s2) - tm.assert_series_equal(s2.append(s1, ignore_index=True), s2) + tm.assert_series_equal(s2._append(s1, ignore_index=True), s2) s1 = Series([], dtype="category") s2 = Series([np.nan, np.nan]) @@ -723,10 +723,10 @@ def test_concat_categorical_empty(self): # empty Series is ignored exp = Series([np.nan, np.nan]) tm.assert_series_equal(pd.concat([s1, s2], ignore_index=True), exp) - tm.assert_series_equal(s1.append(s2, ignore_index=True), exp) + tm.assert_series_equal(s1._append(s2, ignore_index=True), exp) tm.assert_series_equal(pd.concat([s2, s1], ignore_index=True), exp) - tm.assert_series_equal(s2.append(s1, ignore_index=True), exp) + tm.assert_series_equal(s2._append(s1, ignore_index=True), exp) def test_categorical_concat_append(self): cat = Categorical(["a", "b"], categories=["a", "b"]) @@ -737,7 +737,7 @@ def test_categorical_concat_append(self): exp = DataFrame({"cats": cat2, "vals": vals2}, index=Index([0, 1, 0, 1])) tm.assert_frame_equal(pd.concat([df, df]), exp) - tm.assert_frame_equal(df.append(df), exp) + tm.assert_frame_equal(df._append(df), exp) # GH 13524 can concat different categories cat3 = Categorical(["a", "b"], categories=["a", "b", "c"]) @@ -748,5 +748,5 @@ def test_categorical_concat_append(self): exp = DataFrame({"cats": list("abab"), "vals": [1, 2, 1, 2]}) tm.assert_frame_equal(res, exp) - res = df.append(df_different_categories, ignore_index=True) + res = df._append(df_different_categories, ignore_index=True) tm.assert_frame_equal(res, exp) diff --git a/pandas/tests/reshape/concat/test_categorical.py b/pandas/tests/reshape/concat/test_categorical.py index aba14fd2fcd77..93197a1814077 100644 --- a/pandas/tests/reshape/concat/test_categorical.py +++ b/pandas/tests/reshape/concat/test_categorical.py @@ -200,7 +200,7 @@ def test_categorical_concat_gh7864(self): dfx = pd.concat([df1, df2]) tm.assert_index_equal(df["grade"].cat.categories, dfx["grade"].cat.categories) - dfa = df1.append(df2) + dfa = df1._append(df2) tm.assert_index_equal(df["grade"].cat.categories, dfa["grade"].cat.categories) def test_categorical_index_upcast(self): diff --git a/pandas/tests/reshape/concat/test_concat.py b/pandas/tests/reshape/concat/test_concat.py index c4b32371042b3..a7b3c77e6ea0a 100644 --- a/pandas/tests/reshape/concat/test_concat.py +++ b/pandas/tests/reshape/concat/test_concat.py @@ -241,7 +241,7 @@ def test_crossed_dtypes_weird_corner(self): columns=columns, ) - appended = df1.append(df2, ignore_index=True) + appended = concat([df1, df2], ignore_index=True) expected = DataFrame( np.concatenate([df1.values, df2.values], axis=0), columns=columns ) diff --git a/pandas/tests/reshape/concat/test_index.py b/pandas/tests/reshape/concat/test_index.py index 35cf670398664..1692446627914 100644 --- a/pandas/tests/reshape/concat/test_index.py +++ b/pandas/tests/reshape/concat/test_index.py @@ -178,14 +178,14 @@ def test_dups_index(self): tm.assert_frame_equal(result.iloc[10:], df) # append - result = df.iloc[0:8, :].append(df.iloc[8:]) + result = df.iloc[0:8, :]._append(df.iloc[8:]) tm.assert_frame_equal(result, df) - result = df.iloc[0:8, :].append(df.iloc[8:9]).append(df.iloc[9:10]) + result = df.iloc[0:8, :]._append(df.iloc[8:9])._append(df.iloc[9:10]) tm.assert_frame_equal(result, df) expected = concat([df, df], axis=0) - result = df.append(df) + result = df._append(df) tm.assert_frame_equal(result, expected) diff --git a/pandas/tests/reshape/merge/test_merge.py b/pandas/tests/reshape/merge/test_merge.py index 2f9f31ebb0485..4365f61860209 100644 --- a/pandas/tests/reshape/merge/test_merge.py +++ b/pandas/tests/reshape/merge/test_merge.py @@ -686,10 +686,12 @@ def test_join_append_timedeltas(self): # timedelta64 issues with join/merge # GH 5695 - d = {"d": datetime(2013, 11, 5, 5, 56), "t": timedelta(0, 22500)} + d = DataFrame.from_dict( + {"d": [datetime(2013, 11, 5, 5, 56)], "t": [timedelta(0, 22500)]} + ) df = DataFrame(columns=list("dt")) - df = df.append(d, ignore_index=True) - result = df.append(d, ignore_index=True) + df = concat([df, d], ignore_index=True) + result = concat([df, d], ignore_index=True) expected = DataFrame( { "d": [datetime(2013, 11, 5, 5, 56), datetime(2013, 11, 5, 5, 56)], @@ -1176,7 +1178,7 @@ def test_validation(self): tm.assert_frame_equal(result, expected_3) # Dups on right - right_w_dups = right.append(DataFrame({"a": ["e"], "c": ["moo"]}, index=[4])) + right_w_dups = concat([right, DataFrame({"a": ["e"], "c": ["moo"]}, index=[4])]) merge( left, right_w_dups, @@ -1199,8 +1201,8 @@ def test_validation(self): merge(left, right_w_dups, on="a", validate="one_to_one") # Dups on left - left_w_dups = left.append( - DataFrame({"a": ["a"], "c": ["cow"]}, index=[3]), sort=True + left_w_dups = concat( + [left, DataFrame({"a": ["a"], "c": ["cow"]}, index=[3])], sort=True ) merge( left_w_dups, diff --git a/pandas/tests/reshape/test_crosstab.py b/pandas/tests/reshape/test_crosstab.py index 74beda01e4b8a..cc6eec671ac3a 100644 --- a/pandas/tests/reshape/test_crosstab.py +++ b/pandas/tests/reshape/test_crosstab.py @@ -3,6 +3,7 @@ from pandas.core.dtypes.common import is_categorical_dtype +import pandas as pd from pandas import ( CategoricalIndex, DataFrame, @@ -63,7 +64,7 @@ def setup_method(self, method): } ) - self.df = df.append(df, ignore_index=True) + self.df = pd.concat([df, df], ignore_index=True) def test_crosstab_single(self): df = self.df @@ -142,14 +143,14 @@ def test_crosstab_margins(self): exp_cols = df.groupby(["a"]).size().astype("i8") # to keep index.name exp_margin = Series([len(df)], index=Index(["All"], name="a")) - exp_cols = exp_cols.append(exp_margin) + exp_cols = pd.concat([exp_cols, exp_margin]) exp_cols.name = ("All", "") tm.assert_series_equal(all_cols, exp_cols) all_rows = result.loc["All"] exp_rows = df.groupby(["b", "c"]).size().astype("i8") - exp_rows = exp_rows.append(Series([len(df)], index=[("All", "")])) + exp_rows = pd.concat([exp_rows, Series([len(df)], index=[("All", "")])]) exp_rows.name = "All" exp_rows = exp_rows.reindex(all_rows.index) @@ -180,14 +181,14 @@ def test_crosstab_margins_set_margin_name(self): exp_cols = df.groupby(["a"]).size().astype("i8") # to keep index.name exp_margin = Series([len(df)], index=Index(["TOTAL"], name="a")) - exp_cols = exp_cols.append(exp_margin) + exp_cols = pd.concat([exp_cols, exp_margin]) exp_cols.name = ("TOTAL", "") tm.assert_series_equal(all_cols, exp_cols) all_rows = result.loc["TOTAL"] exp_rows = df.groupby(["b", "c"]).size().astype("i8") - exp_rows = exp_rows.append(Series([len(df)], index=[("TOTAL", "")])) + exp_rows = pd.concat([exp_rows, Series([len(df)], index=[("TOTAL", "")])]) exp_rows.name = "TOTAL" exp_rows = exp_rows.reindex(all_rows.index) diff --git a/pandas/tests/series/accessors/test_dt_accessor.py b/pandas/tests/series/accessors/test_dt_accessor.py index 15e13e5567310..41b5e55e75213 100644 --- a/pandas/tests/series/accessors/test_dt_accessor.py +++ b/pandas/tests/series/accessors/test_dt_accessor.py @@ -477,7 +477,7 @@ def test_dt_accessor_datetime_name_accessors(self, time_locale): name = name.capitalize() assert ser.dt.day_name(locale=time_locale)[day] == name assert ser.dt.day_name(locale=None)[day] == eng_name - ser = ser.append(Series([pd.NaT])) + ser = pd.concat([ser, Series([pd.NaT])]) assert np.isnan(ser.dt.day_name(locale=time_locale).iloc[-1]) ser = Series(date_range(freq="M", start="2012", end="2013")) @@ -499,7 +499,7 @@ def test_dt_accessor_datetime_name_accessors(self, time_locale): assert result == expected - ser = ser.append(Series([pd.NaT])) + ser = pd.concat([ser, Series([pd.NaT])]) assert np.isnan(ser.dt.month_name(locale=time_locale).iloc[-1]) def test_strftime(self): diff --git a/pandas/tests/series/indexing/test_indexing.py b/pandas/tests/series/indexing/test_indexing.py index 31c21e123a0de..f6ae886b9e299 100644 --- a/pandas/tests/series/indexing/test_indexing.py +++ b/pandas/tests/series/indexing/test_indexing.py @@ -11,6 +11,7 @@ Series, Timedelta, Timestamp, + concat, date_range, period_range, timedelta_range, @@ -79,6 +80,7 @@ def test_getitem_setitem_ellipsis(): assert (result == 5).all() +@pytest.mark.filterwarnings("ignore:.*append method is deprecated.*:FutureWarning") @pytest.mark.parametrize( "result_1, duplicate_item, expected_1", [ @@ -158,7 +160,7 @@ def test_setitem_ambiguous_keyerror(indexer_sl): # equivalent of an append s2 = s.copy() indexer_sl(s2)[1] = 5 - expected = s.append(Series([5], index=[1])) + expected = concat([s, Series([5], index=[1])]) tm.assert_series_equal(s2, expected) diff --git a/pandas/tests/series/indexing/test_setitem.py b/pandas/tests/series/indexing/test_setitem.py index 3e8e1b3f436ec..0dc2a9933cfc4 100644 --- a/pandas/tests/series/indexing/test_setitem.py +++ b/pandas/tests/series/indexing/test_setitem.py @@ -20,6 +20,7 @@ Series, Timedelta, Timestamp, + concat, date_range, period_range, ) @@ -477,7 +478,7 @@ def test_setitem_not_contained(self, string_series): ser["foobar"] = 1 app = Series([1], index=["foobar"], name="series") - expected = string_series.append(app) + expected = concat([string_series, app]) tm.assert_series_equal(ser, expected) diff --git a/pandas/tests/series/methods/test_append.py b/pandas/tests/series/methods/test_append.py index 2081e244b4e6c..6f8852ade6408 100644 --- a/pandas/tests/series/methods/test_append.py +++ b/pandas/tests/series/methods/test_append.py @@ -15,11 +15,11 @@ class TestSeriesAppend: def test_append_preserve_name(self, datetime_series): - result = datetime_series[:5].append(datetime_series[5:]) + result = datetime_series[:5]._append(datetime_series[5:]) assert result.name == datetime_series.name def test_append(self, datetime_series, string_series, object_series): - appended_series = string_series.append(object_series) + appended_series = string_series._append(object_series) for idx, value in appended_series.items(): if idx in string_series.index: assert value == string_series[idx] @@ -30,12 +30,12 @@ def test_append(self, datetime_series, string_series, object_series): msg = "Indexes have overlapping values:" with pytest.raises(ValueError, match=msg): - datetime_series.append(datetime_series, verify_integrity=True) + datetime_series._append(datetime_series, verify_integrity=True) def test_append_many(self, datetime_series): pieces = [datetime_series[:5], datetime_series[5:10], datetime_series[10:]] - result = pieces[0].append(pieces[1:]) + result = pieces[0]._append(pieces[1:]) tm.assert_series_equal(result, datetime_series) def test_append_duplicates(self): @@ -43,13 +43,13 @@ def test_append_duplicates(self): s1 = Series([1, 2, 3]) s2 = Series([4, 5, 6]) exp = Series([1, 2, 3, 4, 5, 6], index=[0, 1, 2, 0, 1, 2]) - tm.assert_series_equal(s1.append(s2), exp) + tm.assert_series_equal(s1._append(s2), exp) tm.assert_series_equal(pd.concat([s1, s2]), exp) # the result must have RangeIndex exp = Series([1, 2, 3, 4, 5, 6]) tm.assert_series_equal( - s1.append(s2, ignore_index=True), exp, check_index_type=True + s1._append(s2, ignore_index=True), exp, check_index_type=True ) tm.assert_series_equal( pd.concat([s1, s2], ignore_index=True), exp, check_index_type=True @@ -57,7 +57,7 @@ def test_append_duplicates(self): msg = "Indexes have overlapping values:" with pytest.raises(ValueError, match=msg): - s1.append(s2, verify_integrity=True) + s1._append(s2, verify_integrity=True) with pytest.raises(ValueError, match=msg): pd.concat([s1, s2], verify_integrity=True) @@ -67,8 +67,8 @@ def test_append_tuples(self): list_input = [s, s] tuple_input = (s, s) - expected = s.append(list_input) - result = s.append(tuple_input) + expected = s._append(list_input) + result = s._append(tuple_input) tm.assert_series_equal(expected, result) @@ -78,9 +78,14 @@ def test_append_dataframe_raises(self): msg = "to_append should be a Series or list/tuple of Series, got DataFrame" with pytest.raises(TypeError, match=msg): - df.A.append(df) + df.A._append(df) with pytest.raises(TypeError, match=msg): - df.A.append([df]) + df.A._append([df]) + + def test_append_raises_future_warning(self): + # GH#35407 + with tm.assert_produces_warning(FutureWarning): + Series([1, 2]).append(Series([3, 4])) class TestSeriesAppendWithDatetimeIndex: @@ -89,8 +94,8 @@ def test_append(self): ts = Series(np.random.randn(len(rng)), rng) df = DataFrame(np.random.randn(len(rng), 4), index=rng) - result = ts.append(ts) - result_df = df.append(df) + result = ts._append(ts) + result_df = df._append(df) ex_index = DatetimeIndex(np.tile(rng.values, 2)) tm.assert_index_equal(result.index, ex_index) tm.assert_index_equal(result_df.index, ex_index) @@ -107,6 +112,7 @@ def test_append(self): rng2 = rng.copy() rng1.name = "foo" rng2.name = "bar" + assert rng1.append(rng1).name == "foo" assert rng1.append(rng2).name is None @@ -120,8 +126,8 @@ def test_append_tz(self): ts2 = Series(np.random.randn(len(rng2)), rng2) df2 = DataFrame(np.random.randn(len(rng2), 4), index=rng2) - result = ts.append(ts2) - result_df = df.append(df2) + result = ts._append(ts2) + result_df = df._append(df2) tm.assert_index_equal(result.index, rng3) tm.assert_index_equal(result_df.index, rng3) @@ -146,8 +152,8 @@ def test_append_tz_explicit_pytz(self): ts2 = Series(np.random.randn(len(rng2)), rng2) df2 = DataFrame(np.random.randn(len(rng2), 4), index=rng2) - result = ts.append(ts2) - result_df = df.append(df2) + result = ts._append(ts2) + result_df = df._append(df2) tm.assert_index_equal(result.index, rng3) tm.assert_index_equal(result_df.index, rng3) @@ -170,8 +176,8 @@ def test_append_tz_dateutil(self): ts2 = Series(np.random.randn(len(rng2)), rng2) df2 = DataFrame(np.random.randn(len(rng2), 4), index=rng2) - result = ts.append(ts2) - result_df = df.append(df2) + result = ts._append(ts2) + result_df = df._append(df2) tm.assert_index_equal(result.index, rng3) tm.assert_index_equal(result_df.index, rng3) @@ -183,7 +189,7 @@ def test_series_append_aware(self): rng2 = date_range("1/1/2011 02:00", periods=1, freq="H", tz="US/Eastern") ser1 = Series([1], index=rng1) ser2 = Series([2], index=rng2) - ts_result = ser1.append(ser2) + ts_result = ser1._append(ser2) exp_index = DatetimeIndex( ["2011-01-01 01:00", "2011-01-01 02:00"], tz="US/Eastern", freq="H" @@ -196,7 +202,7 @@ def test_series_append_aware(self): rng2 = date_range("1/1/2011 02:00", periods=1, freq="H", tz="UTC") ser1 = Series([1], index=rng1) ser2 = Series([2], index=rng2) - ts_result = ser1.append(ser2) + ts_result = ser1._append(ser2) exp_index = DatetimeIndex( ["2011-01-01 01:00", "2011-01-01 02:00"], tz="UTC", freq="H" @@ -212,7 +218,7 @@ def test_series_append_aware(self): rng2 = date_range("1/1/2011 02:00", periods=1, freq="H", tz="US/Central") ser1 = Series([1], index=rng1) ser2 = Series([2], index=rng2) - ts_result = ser1.append(ser2) + ts_result = ser1._append(ser2) exp_index = Index( [ Timestamp("1/1/2011 01:00", tz="US/Eastern"), @@ -227,7 +233,7 @@ def test_series_append_aware_naive(self): rng2 = date_range("1/1/2011 02:00", periods=1, freq="H", tz="US/Eastern") ser1 = Series(np.random.randn(len(rng1)), index=rng1) ser2 = Series(np.random.randn(len(rng2)), index=rng2) - ts_result = ser1.append(ser2) + ts_result = ser1._append(ser2) expected = ser1.index.astype(object).append(ser2.index.astype(object)) assert ts_result.index.equals(expected) @@ -237,7 +243,7 @@ def test_series_append_aware_naive(self): rng2 = range(100) ser1 = Series(np.random.randn(len(rng1)), index=rng1) ser2 = Series(np.random.randn(len(rng2)), index=rng2) - ts_result = ser1.append(ser2) + ts_result = ser1._append(ser2) expected = ser1.index.astype(object).append(ser2.index) assert ts_result.index.equals(expected) @@ -247,7 +253,7 @@ def test_series_append_dst(self): rng2 = date_range("8/1/2016 01:00", periods=3, freq="H", tz="US/Eastern") ser1 = Series([1, 2, 3], index=rng1) ser2 = Series([10, 11, 12], index=rng2) - ts_result = ser1.append(ser2) + ts_result = ser1._append(ser2) exp_index = DatetimeIndex( [