Skip to content

Commit

Permalink
share test (pandas-dev#37679)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockmendel authored Nov 7, 2020
1 parent 0a5d1cf commit c45da41
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 67 deletions.
38 changes: 24 additions & 14 deletions pandas/tests/frame/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]})
Expand All @@ -294,31 +298,37 @@ 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
else:
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):
Expand Down
53 changes: 0 additions & 53 deletions pandas/tests/series/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand All @@ -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

0 comments on commit c45da41

Please sign in to comment.