diff --git a/pandas/tests/frame/test_api.py b/pandas/tests/frame/test_api.py index 25d3fab76ca36..157c8687808b3 100644 --- a/pandas/tests/frame/test_api.py +++ b/pandas/tests/frame/test_api.py @@ -263,12 +263,16 @@ def _check_f(base, f): @async_mark() @td.check_file_leaks - async def test_tab_complete_warning(self, ip): + async def test_tab_complete_warning(self, ip, frame_or_series): # GH 16409 pytest.importorskip("IPython", minversion="6.0.0") from IPython.core.completer import provisionalcompleter - code = "from pandas import DataFrame; df = DataFrame()" + if frame_or_series is DataFrame: + code = "from pandas import DataFrame; obj = DataFrame()" + else: + code = "from pandas import Series; obj = Series(dtype=object)" + await ip.run_code(code) # TODO: remove it when Ipython updates @@ -283,7 +287,7 @@ async def test_tab_complete_warning(self, ip): ) with warning: with provisionalcompleter("ignore"): - list(ip.Completer.completions("df.", 1)) + list(ip.Completer.completions("obj.", 1)) def test_attrs(self): df = DataFrame({"A": [2, 3]}) @@ -294,9 +298,15 @@ def test_attrs(self): assert result.attrs == {"version": 1} @pytest.mark.parametrize("allows_duplicate_labels", [True, False, None]) - def test_set_flags(self, allows_duplicate_labels): - df = DataFrame({"A": [1, 2]}) - result = df.set_flags(allows_duplicate_labels=allows_duplicate_labels) + def test_set_flags(self, allows_duplicate_labels, frame_or_series): + obj = DataFrame({"A": [1, 2]}) + key = (0, 0) + if frame_or_series is Series: + obj = obj["A"] + key = 0 + + result = obj.set_flags(allows_duplicate_labels=allows_duplicate_labels) + if allows_duplicate_labels is None: # We don't update when it's not provided assert result.flags.allows_duplicate_labels is True @@ -304,21 +314,21 @@ def test_set_flags(self, allows_duplicate_labels): assert result.flags.allows_duplicate_labels is allows_duplicate_labels # We made a copy - assert df is not result + assert obj is not result - # We didn't mutate df - assert df.flags.allows_duplicate_labels is True + # We didn't mutate obj + assert obj.flags.allows_duplicate_labels is True # But we didn't copy data - result.iloc[0, 0] = 0 - assert df.iloc[0, 0] == 0 + result.iloc[key] = 0 + assert obj.iloc[key] == 0 # Now we do copy. - result = df.set_flags( + result = obj.set_flags( copy=True, allows_duplicate_labels=allows_duplicate_labels ) - result.iloc[0, 0] = 10 - assert df.iloc[0, 0] == 0 + result.iloc[key] = 10 + assert obj.iloc[key] == 0 @skip_if_no("jinja2") def test_constructor_expanddim_lookup(self): diff --git a/pandas/tests/series/test_api.py b/pandas/tests/series/test_api.py index 717d8b5c90d85..beace074894a8 100644 --- a/pandas/tests/series/test_api.py +++ b/pandas/tests/series/test_api.py @@ -3,9 +3,6 @@ import numpy as np import pytest -import pandas.util._test_decorators as td -from pandas.util._test_decorators import async_mark - import pandas as pd from pandas import DataFrame, Index, Series, Timedelta, Timestamp, date_range import pandas._testing as tm @@ -216,30 +213,6 @@ def test_empty_method(self): for full_series in [Series([1]), s2]: assert not full_series.empty - @async_mark() - @td.check_file_leaks - async def test_tab_complete_warning(self, ip): - # https://github.com/pandas-dev/pandas/issues/16409 - pytest.importorskip("IPython", minversion="6.0.0") - from IPython.core.completer import provisionalcompleter - - code = "import pandas as pd; s = Series(dtype=object)" - await ip.run_code(code) - - # TODO: remove it when Ipython updates - # GH 33567, jedi version raises Deprecation warning in Ipython - import jedi - - if jedi.__version__ < "0.17.0": - warning = tm.assert_produces_warning(None) - else: - warning = tm.assert_produces_warning( - DeprecationWarning, check_stacklevel=False - ) - with warning: - with provisionalcompleter("ignore"): - list(ip.Completer.completions("s.", 1)) - def test_integer_series_size(self): # GH 25580 s = Series(range(9)) @@ -253,29 +226,3 @@ def test_attrs(self): s.attrs["version"] = 1 result = s + 1 assert result.attrs == {"version": 1} - - @pytest.mark.parametrize("allows_duplicate_labels", [True, False, None]) - def test_set_flags(self, allows_duplicate_labels): - df = Series([1, 2]) - result = df.set_flags(allows_duplicate_labels=allows_duplicate_labels) - if allows_duplicate_labels is None: - # We don't update when it's not provided - assert result.flags.allows_duplicate_labels is True - else: - assert result.flags.allows_duplicate_labels is allows_duplicate_labels - - # We made a copy - assert df is not result - # We didn't mutate df - assert df.flags.allows_duplicate_labels is True - - # But we didn't copy data - result.iloc[0] = 0 - assert df.iloc[0] == 0 - - # Now we do copy. - result = df.set_flags( - copy=True, allows_duplicate_labels=allows_duplicate_labels - ) - result.iloc[0] = 10 - assert df.iloc[0] == 0