Skip to content

TST: misplaced Series.get test #32876

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 2 commits into from
Mar 21, 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
23 changes: 3 additions & 20 deletions pandas/tests/generic/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ def finalize(self, other, method=None, **kwargs):
Series._metadata = _metadata
Series.__finalize__ = _finalize # FIXME: use monkeypatch


class TestSeries2:
# Separating off because it doesnt rely on parent class
@pytest.mark.parametrize(
"s",
[
Expand All @@ -196,26 +199,6 @@ def test_datetime_shift_always_copy(self, move_by_freq):
assert s.shift(freq=move_by_freq) is not s


class TestSeries2:
# moved from Generic
def test_get_default(self):

# GH#7725
d0 = ["a", "b", "c", "d"]
d1 = np.arange(4, dtype="int64")
others = ["e", 10]

for data, index in ((d0, d1), (d1, d0)):
s = Series(data, index=index)
for i, d in zip(index, data):
assert s.get(i) == d
assert s.get(i, d) == d
assert s.get(i, "z") == d
for other in others:
assert s.get(other, "z") == "z"
assert s.get(other, other) == other


class TestToXArray:
@pytest.mark.skipif(
not _XARRAY_INSTALLED
Expand Down
17 changes: 17 additions & 0 deletions pandas/tests/series/indexing/test_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,20 @@ def test_get_nan_multiple():

idx = [np.nan, np.nan]
assert s.get(idx) is None


def test_get_with_default():
# GH#7725
d0 = ["a", "b", "c", "d"]
d1 = np.arange(4, dtype="int64")
others = ["e", 10]

for data, index in ((d0, d1), (d1, d0)):
s = Series(data, index=index)
for i, d in zip(index, data):
assert s.get(i) == d
assert s.get(i, d) == d
assert s.get(i, "z") == d
for other in others:
assert s.get(other, "z") == "z"
assert s.get(other, other) == other
15 changes: 2 additions & 13 deletions pandas/tests/series/test_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,6 @@
import pandas._testing as tm


def _simple_ts(start, end, freq="D"):
rng = date_range(start, end, freq=freq)
return Series(np.random.randn(len(rng)), index=rng)


def assert_range_equal(left, right):
assert left.equals(right)
assert left.freq == right.freq
assert left.tz == right.tz


class TestTimeSeries:
def test_autocorr(self, datetime_series):
# Just run the function
Expand Down Expand Up @@ -72,8 +61,8 @@ def test_contiguous_boolean_preserve_freq(self):

masked = rng[mask]
expected = rng[10:20]
assert expected.freq is not None
assert_range_equal(masked, expected)
assert expected.freq == rng.freq
tm.assert_index_equal(masked, expected)

mask[22] = True
masked = rng[mask]
Expand Down