Skip to content

Commit 83a2e7f

Browse files
authored
TST/REF: collect Index tests by method (#39873)
1 parent 935000e commit 83a2e7f

File tree

11 files changed

+327
-301
lines changed

11 files changed

+327
-301
lines changed

pandas/tests/indexes/common.py

+2-8
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,6 @@ def test_copy_name2(self, index):
243243
with pytest.raises(TypeError, match=msg):
244244
index.copy(name=[["mario"]])
245245

246-
def test_copy_dtype_deprecated(self, index):
247-
# GH35853
248-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
249-
index.copy(dtype=object)
250-
251246
def test_ensure_copied_data(self, index):
252247
# Check the "copy" argument of each Index.__new__ is honoured
253248
# GH12309
@@ -504,10 +499,9 @@ def test_format_empty(self):
504499
assert empty_idx.format() == []
505500
assert empty_idx.format(name=True) == [""]
506501

507-
def test_hasnans_isnans(self, index):
502+
def test_hasnans_isnans(self, index_flat):
508503
# GH 11343, added tests for hasnans / isnans
509-
if isinstance(index, MultiIndex):
510-
return
504+
index = index_flat
511505

512506
# cases in indices doesn't include NaN
513507
idx = index.copy(deep=True)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from pandas import (
2+
DataFrame,
3+
date_range,
4+
)
5+
import pandas._testing as tm
6+
7+
8+
class TestToFrame:
9+
def test_to_frame_datetime_tz(self):
10+
# GH#25809
11+
idx = date_range(start="2019-01-01", end="2019-01-30", freq="D", tz="UTC")
12+
result = idx.to_frame()
13+
expected = DataFrame(idx, index=idx)
14+
tm.assert_frame_equal(result, expected)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from pandas import (
2+
Index,
3+
Timestamp,
4+
date_range,
5+
)
6+
7+
8+
class TestAsOf:
9+
def test_asof_partial(self):
10+
index = date_range("2010-01-01", periods=2, freq="m")
11+
expected = Timestamp("2010-02-28")
12+
result = index.asof("2010-02")
13+
assert result == expected
14+
assert not isinstance(result, Index)

pandas/tests/indexes/datetimes/test_datetime.py

-7
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,3 @@ def test_asarray_tz_aware(self):
240240
result = np.asarray(idx, dtype=object)
241241

242242
tm.assert_numpy_array_equal(result, expected)
243-
244-
def test_to_frame_datetime_tz(self):
245-
# GH 25809
246-
idx = date_range(start="2019-01-01", end="2019-01-30", freq="D", tz="UTC")
247-
result = idx.to_frame()
248-
expected = DataFrame(idx, index=idx)
249-
tm.assert_frame_equal(result, expected)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import numpy as np
2+
import pytest
3+
4+
from pandas import (
5+
NaT,
6+
PeriodIndex,
7+
period_range,
8+
)
9+
import pandas._testing as tm
10+
11+
12+
class TestInsert:
13+
@pytest.mark.parametrize("na", [np.nan, NaT, None])
14+
def test_insert(self, na):
15+
# GH#18295 (test missing)
16+
expected = PeriodIndex(["2017Q1", NaT, "2017Q2", "2017Q3", "2017Q4"], freq="Q")
17+
result = period_range("2017Q1", periods=4, freq="Q").insert(1, na)
18+
tm.assert_index_equal(result, expected)

pandas/tests/indexes/period/test_constructors.py

+21
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,27 @@ def test_map_with_string_constructor(self):
512512
tm.assert_index_equal(res, expected)
513513

514514

515+
class TestShallowCopy:
516+
def test_shallow_copy_empty(self):
517+
# GH#13067
518+
idx = PeriodIndex([], freq="M")
519+
result = idx._view()
520+
expected = idx
521+
522+
tm.assert_index_equal(result, expected)
523+
524+
def test_shallow_copy_disallow_i8(self):
525+
# GH#24391
526+
pi = period_range("2018-01-01", periods=3, freq="2D")
527+
with pytest.raises(AssertionError, match="ndarray"):
528+
pi._shallow_copy(pi.asi8)
529+
530+
def test_shallow_copy_requires_disallow_period_index(self):
531+
pi = period_range("2018-01-01", periods=3, freq="2D")
532+
with pytest.raises(AssertionError, match="PeriodIndex"):
533+
pi._shallow_copy(pi)
534+
535+
515536
class TestSeriesPeriod:
516537
def setup_method(self, method):
517538
self.series = Series(period_range("2000-01-01", periods=10, freq="D"))

pandas/tests/indexes/period/test_period.py

+1-27
Original file line numberDiff line numberDiff line change
@@ -79,25 +79,6 @@ def test_make_time_series(self):
7979
series = Series(1, index=index)
8080
assert isinstance(series, Series)
8181

82-
def test_shallow_copy_empty(self):
83-
# GH13067
84-
idx = PeriodIndex([], freq="M")
85-
result = idx._view()
86-
expected = idx
87-
88-
tm.assert_index_equal(result, expected)
89-
90-
def test_shallow_copy_disallow_i8(self):
91-
# GH-24391
92-
pi = period_range("2018-01-01", periods=3, freq="2D")
93-
with pytest.raises(AssertionError, match="ndarray"):
94-
pi._shallow_copy(pi.asi8)
95-
96-
def test_shallow_copy_requires_disallow_period_index(self):
97-
pi = period_range("2018-01-01", periods=3, freq="2D")
98-
with pytest.raises(AssertionError, match="PeriodIndex"):
99-
pi._shallow_copy(pi)
100-
10182
def test_view_asi8(self):
10283
idx = PeriodIndex([], freq="M")
10384

@@ -411,7 +392,7 @@ def test_convert_array_of_periods(self):
411392
result = Index(periods)
412393
assert isinstance(result, PeriodIndex)
413394

414-
def test_append_concat(self):
395+
def test_append_concat(self): # TODO: pd.concat test
415396
# #1815
416397
d1 = date_range("12/31/1990", "12/31/1999", freq="A-DEC")
417398
d2 = date_range("12/31/2000", "12/31/2009", freq="A-DEC")
@@ -442,13 +423,6 @@ def test_map(self):
442423
exp = Index([x.ordinal for x in index])
443424
tm.assert_index_equal(result, exp)
444425

445-
def test_insert(self):
446-
# GH 18295 (test missing)
447-
expected = PeriodIndex(["2017Q1", NaT, "2017Q2", "2017Q3", "2017Q4"], freq="Q")
448-
for na in (np.nan, NaT, None):
449-
result = period_range("2017Q1", periods=4, freq="Q").insert(1, na)
450-
tm.assert_index_equal(result, expected)
451-
452426
@pytest.mark.parametrize(
453427
"msg, key",
454428
[

0 commit comments

Comments
 (0)