Skip to content

TST/REF: collect Index tests by method #39873

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

Merged
merged 6 commits into from
Feb 21, 2021
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
10 changes: 2 additions & 8 deletions pandas/tests/indexes/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,6 @@ def test_copy_name2(self, index):
with pytest.raises(TypeError, match=msg):
index.copy(name=[["mario"]])

def test_copy_dtype_deprecated(self, index):
# GH35853
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
index.copy(dtype=object)

def test_ensure_copied_data(self, index):
# Check the "copy" argument of each Index.__new__ is honoured
# GH12309
Expand Down Expand Up @@ -504,10 +499,9 @@ def test_format_empty(self):
assert empty_idx.format() == []
assert empty_idx.format(name=True) == [""]

def test_hasnans_isnans(self, index):
def test_hasnans_isnans(self, index_flat):
# GH 11343, added tests for hasnans / isnans
if isinstance(index, MultiIndex):
return
index = index_flat

# cases in indices doesn't include NaN
idx = index.copy(deep=True)
Expand Down
14 changes: 14 additions & 0 deletions pandas/tests/indexes/datetimes/methods/test_to_frame.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from pandas import (
DataFrame,
date_range,
)
import pandas._testing as tm


class TestToFrame:
def test_to_frame_datetime_tz(self):
# GH#25809
idx = date_range(start="2019-01-01", end="2019-01-30", freq="D", tz="UTC")
result = idx.to_frame()
expected = DataFrame(idx, index=idx)
tm.assert_frame_equal(result, expected)
14 changes: 14 additions & 0 deletions pandas/tests/indexes/datetimes/test_asof.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from pandas import (
Index,
Timestamp,
date_range,
)


class TestAsOf:
def test_asof_partial(self):
index = date_range("2010-01-01", periods=2, freq="m")
expected = Timestamp("2010-02-28")
result = index.asof("2010-02")
assert result == expected
assert not isinstance(result, Index)
7 changes: 0 additions & 7 deletions pandas/tests/indexes/datetimes/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,3 @@ def test_asarray_tz_aware(self):
result = np.asarray(idx, dtype=object)

tm.assert_numpy_array_equal(result, expected)

def test_to_frame_datetime_tz(self):
# GH 25809
idx = date_range(start="2019-01-01", end="2019-01-30", freq="D", tz="UTC")
result = idx.to_frame()
expected = DataFrame(idx, index=idx)
tm.assert_frame_equal(result, expected)
18 changes: 18 additions & 0 deletions pandas/tests/indexes/period/methods/test_insert.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import numpy as np
import pytest

from pandas import (
NaT,
PeriodIndex,
period_range,
)
import pandas._testing as tm


class TestInsert:
@pytest.mark.parametrize("na", [np.nan, NaT, None])
def test_insert(self, na):
# GH#18295 (test missing)
expected = PeriodIndex(["2017Q1", NaT, "2017Q2", "2017Q3", "2017Q4"], freq="Q")
result = period_range("2017Q1", periods=4, freq="Q").insert(1, na)
tm.assert_index_equal(result, expected)
21 changes: 21 additions & 0 deletions pandas/tests/indexes/period/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,27 @@ def test_map_with_string_constructor(self):
tm.assert_index_equal(res, expected)


class TestShallowCopy:
def test_shallow_copy_empty(self):
# GH#13067
idx = PeriodIndex([], freq="M")
result = idx._view()
expected = idx

tm.assert_index_equal(result, expected)

def test_shallow_copy_disallow_i8(self):
# GH#24391
pi = period_range("2018-01-01", periods=3, freq="2D")
with pytest.raises(AssertionError, match="ndarray"):
pi._shallow_copy(pi.asi8)

def test_shallow_copy_requires_disallow_period_index(self):
pi = period_range("2018-01-01", periods=3, freq="2D")
with pytest.raises(AssertionError, match="PeriodIndex"):
pi._shallow_copy(pi)


class TestSeriesPeriod:
def setup_method(self, method):
self.series = Series(period_range("2000-01-01", periods=10, freq="D"))
Expand Down
28 changes: 1 addition & 27 deletions pandas/tests/indexes/period/test_period.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,25 +79,6 @@ def test_make_time_series(self):
series = Series(1, index=index)
assert isinstance(series, Series)

def test_shallow_copy_empty(self):
# GH13067
idx = PeriodIndex([], freq="M")
result = idx._view()
expected = idx

tm.assert_index_equal(result, expected)

def test_shallow_copy_disallow_i8(self):
# GH-24391
pi = period_range("2018-01-01", periods=3, freq="2D")
with pytest.raises(AssertionError, match="ndarray"):
pi._shallow_copy(pi.asi8)

def test_shallow_copy_requires_disallow_period_index(self):
pi = period_range("2018-01-01", periods=3, freq="2D")
with pytest.raises(AssertionError, match="PeriodIndex"):
pi._shallow_copy(pi)

def test_view_asi8(self):
idx = PeriodIndex([], freq="M")

Expand Down Expand Up @@ -411,7 +392,7 @@ def test_convert_array_of_periods(self):
result = Index(periods)
assert isinstance(result, PeriodIndex)

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

def test_insert(self):
# GH 18295 (test missing)
expected = PeriodIndex(["2017Q1", NaT, "2017Q2", "2017Q3", "2017Q4"], freq="Q")
for na in (np.nan, NaT, None):
result = period_range("2017Q1", periods=4, freq="Q").insert(1, na)
tm.assert_index_equal(result, expected)

@pytest.mark.parametrize(
"msg, key",
[
Expand Down
Loading