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

REF/TST: share some api tests #37679

Merged
merged 2 commits into from
Nov 7, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
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)"
Copy link
Member Author

Choose a reason for hiding this comment

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

shouldn't this be s = pd.Series instead of s = Series? I made this change above, but a bit concerned that it isn't failing in master.

Copy link
Contributor

Choose a reason for hiding this comment

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

not sure i understand the comment; the test seems to be passing?

Copy link
Member Author

Choose a reason for hiding this comment

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

how is Series in the namespace? it it getting it from the file namespace? if so, why bother with importing pd?

I guess my concern is that it is passing because it isnt actually testing what its supposed to

Copy link
Contributor

Choose a reason for hiding this comment

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

ahh i see what you mean. no guarantee that this is not currently skipped; i see you re-wrote it anyhow.

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