Skip to content

Commit c45da41

Browse files
authored
share test (#37679)
1 parent 0a5d1cf commit c45da41

File tree

2 files changed

+24
-67
lines changed

2 files changed

+24
-67
lines changed

pandas/tests/frame/test_api.py

+24-14
Original file line numberDiff line numberDiff line change
@@ -263,12 +263,16 @@ def _check_f(base, f):
263263

264264
@async_mark()
265265
@td.check_file_leaks
266-
async def test_tab_complete_warning(self, ip):
266+
async def test_tab_complete_warning(self, ip, frame_or_series):
267267
# GH 16409
268268
pytest.importorskip("IPython", minversion="6.0.0")
269269
from IPython.core.completer import provisionalcompleter
270270

271-
code = "from pandas import DataFrame; df = DataFrame()"
271+
if frame_or_series is DataFrame:
272+
code = "from pandas import DataFrame; obj = DataFrame()"
273+
else:
274+
code = "from pandas import Series; obj = Series(dtype=object)"
275+
272276
await ip.run_code(code)
273277

274278
# TODO: remove it when Ipython updates
@@ -283,7 +287,7 @@ async def test_tab_complete_warning(self, ip):
283287
)
284288
with warning:
285289
with provisionalcompleter("ignore"):
286-
list(ip.Completer.completions("df.", 1))
290+
list(ip.Completer.completions("obj.", 1))
287291

288292
def test_attrs(self):
289293
df = DataFrame({"A": [2, 3]})
@@ -294,31 +298,37 @@ def test_attrs(self):
294298
assert result.attrs == {"version": 1}
295299

296300
@pytest.mark.parametrize("allows_duplicate_labels", [True, False, None])
297-
def test_set_flags(self, allows_duplicate_labels):
298-
df = DataFrame({"A": [1, 2]})
299-
result = df.set_flags(allows_duplicate_labels=allows_duplicate_labels)
301+
def test_set_flags(self, allows_duplicate_labels, frame_or_series):
302+
obj = DataFrame({"A": [1, 2]})
303+
key = (0, 0)
304+
if frame_or_series is Series:
305+
obj = obj["A"]
306+
key = 0
307+
308+
result = obj.set_flags(allows_duplicate_labels=allows_duplicate_labels)
309+
300310
if allows_duplicate_labels is None:
301311
# We don't update when it's not provided
302312
assert result.flags.allows_duplicate_labels is True
303313
else:
304314
assert result.flags.allows_duplicate_labels is allows_duplicate_labels
305315

306316
# We made a copy
307-
assert df is not result
317+
assert obj is not result
308318

309-
# We didn't mutate df
310-
assert df.flags.allows_duplicate_labels is True
319+
# We didn't mutate obj
320+
assert obj.flags.allows_duplicate_labels is True
311321

312322
# But we didn't copy data
313-
result.iloc[0, 0] = 0
314-
assert df.iloc[0, 0] == 0
323+
result.iloc[key] = 0
324+
assert obj.iloc[key] == 0
315325

316326
# Now we do copy.
317-
result = df.set_flags(
327+
result = obj.set_flags(
318328
copy=True, allows_duplicate_labels=allows_duplicate_labels
319329
)
320-
result.iloc[0, 0] = 10
321-
assert df.iloc[0, 0] == 0
330+
result.iloc[key] = 10
331+
assert obj.iloc[key] == 0
322332

323333
@skip_if_no("jinja2")
324334
def test_constructor_expanddim_lookup(self):

pandas/tests/series/test_api.py

-53
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
import numpy as np
44
import pytest
55

6-
import pandas.util._test_decorators as td
7-
from pandas.util._test_decorators import async_mark
8-
96
import pandas as pd
107
from pandas import DataFrame, Index, Series, Timedelta, Timestamp, date_range
118
import pandas._testing as tm
@@ -216,30 +213,6 @@ def test_empty_method(self):
216213
for full_series in [Series([1]), s2]:
217214
assert not full_series.empty
218215

219-
@async_mark()
220-
@td.check_file_leaks
221-
async def test_tab_complete_warning(self, ip):
222-
# https://github.com/pandas-dev/pandas/issues/16409
223-
pytest.importorskip("IPython", minversion="6.0.0")
224-
from IPython.core.completer import provisionalcompleter
225-
226-
code = "import pandas as pd; s = Series(dtype=object)"
227-
await ip.run_code(code)
228-
229-
# TODO: remove it when Ipython updates
230-
# GH 33567, jedi version raises Deprecation warning in Ipython
231-
import jedi
232-
233-
if jedi.__version__ < "0.17.0":
234-
warning = tm.assert_produces_warning(None)
235-
else:
236-
warning = tm.assert_produces_warning(
237-
DeprecationWarning, check_stacklevel=False
238-
)
239-
with warning:
240-
with provisionalcompleter("ignore"):
241-
list(ip.Completer.completions("s.", 1))
242-
243216
def test_integer_series_size(self):
244217
# GH 25580
245218
s = Series(range(9))
@@ -253,29 +226,3 @@ def test_attrs(self):
253226
s.attrs["version"] = 1
254227
result = s + 1
255228
assert result.attrs == {"version": 1}
256-
257-
@pytest.mark.parametrize("allows_duplicate_labels", [True, False, None])
258-
def test_set_flags(self, allows_duplicate_labels):
259-
df = Series([1, 2])
260-
result = df.set_flags(allows_duplicate_labels=allows_duplicate_labels)
261-
if allows_duplicate_labels is None:
262-
# We don't update when it's not provided
263-
assert result.flags.allows_duplicate_labels is True
264-
else:
265-
assert result.flags.allows_duplicate_labels is allows_duplicate_labels
266-
267-
# We made a copy
268-
assert df is not result
269-
# We didn't mutate df
270-
assert df.flags.allows_duplicate_labels is True
271-
272-
# But we didn't copy data
273-
result.iloc[0] = 0
274-
assert df.iloc[0] == 0
275-
276-
# Now we do copy.
277-
result = df.set_flags(
278-
copy=True, allows_duplicate_labels=allows_duplicate_labels
279-
)
280-
result.iloc[0] = 10
281-
assert df.iloc[0] == 0

0 commit comments

Comments
 (0)