Skip to content
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

DEPR: Series/DataFrame.append (#35407) #44539

Merged
merged 38 commits into from
Dec 27, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
c1289e9
DEPR: Series/DataFrame.append (#35407)
neinkeinkaffee Nov 20, 2021
7d96d25
Refer to pandas.concat instead of pandas.core.reshape.concat
neinkeinkaffee Nov 20, 2021
963d151
Add explicit test for warning, ignore in the remainder of the tests
neinkeinkaffee Nov 20, 2021
2b818bb
Refer to concat in root namespace
neinkeinkaffee Nov 20, 2021
153a784
Fix copy-paste errors
neinkeinkaffee Nov 20, 2021
98d0f9c
Ignore warning in reshape/concat test_append and add issue reference
neinkeinkaffee Nov 21, 2021
10ef0b6
Ignore warnings in reshape test_crosstab
neinkeinkaffee Nov 21, 2021
becc29f
Replace further appends with concat
neinkeinkaffee Nov 29, 2021
bdf2484
Merge branch 'master' into 35407-deprecate-append
neinkeinkaffee Nov 29, 2021
02620b8
Ignore FutureWarning in test_value_counts_null
neinkeinkaffee Nov 30, 2021
bc9f6dc
Merge branch 'master' into 35407-deprecate-append
neinkeinkaffee Nov 30, 2021
7b9fdf3
Filter FutureWarning in remaining affected tests
neinkeinkaffee Nov 30, 2021
bf2f30c
Ignore FutureWarning in even more tests
neinkeinkaffee Nov 30, 2021
982250d
Ignore FutureWarning in one last test
neinkeinkaffee Nov 30, 2021
fbdbc24
Delete refs to merging.concatenation and merging.append.row (document…
neinkeinkaffee Nov 30, 2021
506868b
Replace append by concat in tests instead of ignoring warnings
neinkeinkaffee Dec 1, 2021
525297b
Introduce intermediate variables
neinkeinkaffee Dec 1, 2021
e19b2e1
Use ipython instead of code block
neinkeinkaffee Dec 1, 2021
18f45fe
Merge branch 'master' into 35407-deprecate-append
neinkeinkaffee Dec 1, 2021
ca851c4
Extract _append and replace append by _append/concat in tests with ig…
neinkeinkaffee Dec 2, 2021
2be9010
Reinsert modified instructions for appending one row to df (suggestion)
neinkeinkaffee Dec 3, 2021
f397503
Merge master
neinkeinkaffee Dec 3, 2021
028b012
Import concat from pandas in tests
neinkeinkaffee Dec 4, 2021
1d8f3c5
Fit call to concat on one line
neinkeinkaffee Dec 4, 2021
4107ec3
Merge branch 'master' into 35407-deprecate-append
neinkeinkaffee Dec 4, 2021
d319b0f
Replace append by concat in _add_margins
neinkeinkaffee Dec 4, 2021
7f9cb7c
Merge commit '4bacee5a69f0e95c19638426553eb3fa24fe6c96' into 35407-de…
neinkeinkaffee Dec 5, 2021
46170d4
Replace append and _append by concat in tests
neinkeinkaffee Dec 5, 2021
caf1983
Import concat from pandas instead of locally from submodule
neinkeinkaffee Dec 5, 2021
aa90ca6
Test DataFrame._append where DataFrame.append is subject under test
neinkeinkaffee Dec 8, 2021
b673e4b
Extract variable and improve variable name
neinkeinkaffee Dec 8, 2021
e0492bc
Introduce Series._append and use in test_append and frame.py
neinkeinkaffee Dec 8, 2021
569abb1
Catch two more tests that should test _append
neinkeinkaffee Dec 8, 2021
c43ea63
Revert append -> concat and use _append internally instead
neinkeinkaffee Dec 8, 2021
0c99fab
Merge master
neinkeinkaffee Dec 24, 2021
f6586c8
Remove in-place append of single rows from the docs
neinkeinkaffee Dec 25, 2021
4e065f5
Merge branch 'master' into 35407-deprecate-append
neinkeinkaffee Dec 26, 2021
430355b
Merge branch 'master' into 35407-deprecate-append
neinkeinkaffee Dec 27, 2021
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
8 changes: 2 additions & 6 deletions pandas/tests/generic/test_duplicate_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,15 +294,11 @@ def test_setting_allows_duplicate_labels_raises(self, data):

assert data.flags.allows_duplicate_labels is True

@pytest.mark.filterwarnings("ignore:.*append method is deprecated.*:FutureWarning")
@pytest.mark.parametrize(
"func", [operator.methodcaller("append", pd.Series(0, index=["a", "b"]))]
)
def test_series_raises(self, func):
def test_series_raises(self):
s = 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([pd.Series(0, index=["a", "b"]), s])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you construct the series outside of the pytest.raises; makes clearer exactly what part of this line is raising


@pytest.mark.parametrize(
"getter, target",
Expand Down
5 changes: 3 additions & 2 deletions pandas/tests/indexing/test_partial.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"))
s = Series(df.iloc[0], name="a")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"s" -> "ser" pls

exp = pd.concat([orig, DataFrame(s).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"
Expand Down
5 changes: 0 additions & 5 deletions pandas/tests/reshape/concat/test_categorical.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import numpy as np
import pytest

from pandas.core.dtypes.dtypes import CategoricalDtype

Expand Down Expand Up @@ -185,7 +184,6 @@ def test_concat_categorical_unchanged(self):
)
tm.assert_equal(result, expected)

@pytest.mark.filterwarnings("ignore:.*append method is deprecated.*:FutureWarning")
def test_categorical_concat_gh7864(self):
# GH 7864
# make sure ordering is preserved
Expand All @@ -202,9 +200,6 @@ 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)
tm.assert_index_equal(df["grade"].cat.categories, dfa["grade"].cat.categories)

def test_categorical_index_upcast(self):
# GH 17629
# test upcasting to object when concatinating on categorical indexes
Expand Down
3 changes: 1 addition & 2 deletions pandas/tests/reshape/concat/test_concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ def test_concat_keys_levels_no_overlap(self):
with pytest.raises(ValueError, match=msg):
concat([df, df2], keys=["one", "two"], levels=[["foo", "bar", "baz"]])

@pytest.mark.filterwarnings("ignore:.*append method is deprecated.*:FutureWarning")
def test_crossed_dtypes_weird_corner(self):
columns = ["A", "B", "C", "D"]
df1 = DataFrame(
Expand All @@ -242,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
)
Expand Down
9 changes: 2 additions & 7 deletions pandas/tests/reshape/concat/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ def test_default_index(self):
exp = DataFrame([[1, 5, 3, 7], [2, 6, 4, 8]])
tm.assert_frame_equal(res, exp, check_index_type=True, check_column_type=True)

@pytest.mark.filterwarnings("ignore:.*append method is deprecated.*:FutureWarning")
def test_dups_index(self):
# GH 4771

Expand Down Expand Up @@ -179,16 +178,12 @@ def test_dups_index(self):
tm.assert_frame_equal(result.iloc[10:], df)

# append
result = df.iloc[0:8, :].append(df.iloc[8:])
result = concat([df.iloc[0:8, :], df.iloc[8:]])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these redundant with the tests above? this may be better thought of as a targeted test for _append.

tm.assert_frame_equal(result, df)

result = df.iloc[0:8, :].append(df.iloc[8:9]).append(df.iloc[9:10])
result = concat([df.iloc[0:8, :], df.iloc[8:9], df.iloc[9:10]])
tm.assert_frame_equal(result, df)

expected = concat([df, df], axis=0)
result = df.append(df)
tm.assert_frame_equal(result, expected)


class TestMultiIndexConcat:
def test_concat_multiindex_with_keys(self, multiindex_dataframe_random_data):
Expand Down
9 changes: 5 additions & 4 deletions pandas/tests/reshape/merge/test_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,15 +682,16 @@ def _constructor(self):

assert isinstance(result, NotADataFrame)

@pytest.mark.filterwarnings("ignore:.*append method is deprecated.*:FutureWarning")
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)],
Expand Down