Skip to content

CLN: misplaced indexing tests #44375

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
Nov 11, 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
33 changes: 33 additions & 0 deletions pandas/tests/arithmetic/test_datetime64.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,39 @@ def test_dt64arr_timestamp_equality(self, box_with_array):
expected = tm.box_expected([False, False, False], xbox)
tm.assert_equal(result, expected)

@pytest.mark.parametrize(
"datetimelike",
[
Timestamp("20130101"),
datetime(2013, 1, 1),
np.datetime64("2013-01-01T00:00", "ns"),
],
)
@pytest.mark.parametrize(
"op,expected",
[
(operator.lt, [True, False, False, False]),
(operator.le, [True, True, False, False]),
(operator.eq, [False, True, False, False]),
(operator.gt, [False, False, False, True]),
],
)
def test_dt64_compare_datetime_scalar(self, datetimelike, op, expected):
# GH#17965, test for ability to compare datetime64[ns] columns
# to datetimelike
ser = Series(
[
Timestamp("20120101"),
Timestamp("20130101"),
np.nan,
Timestamp("20130103"),
],
name="A",
)
result = op(ser, datetimelike)
expected = Series(expected, name="A")
tm.assert_series_equal(result, expected)


class TestDatetimeIndexComparisons:

Expand Down
35 changes: 0 additions & 35 deletions pandas/tests/indexes/datetimes/test_partial_slicing.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
""" test partial slicing on Series/Frame """

from datetime import datetime
import operator

import numpy as np
import pytest
Expand Down Expand Up @@ -412,40 +411,6 @@ def test_loc_datetime_length_one(self):
result = df.loc["2016-10-01T00:00:00":]
tm.assert_frame_equal(result, df)

@pytest.mark.parametrize(
"datetimelike",
[
Timestamp("20130101"),
datetime(2013, 1, 1),
np.datetime64("2013-01-01T00:00", "ns"),
],
)
@pytest.mark.parametrize(
"op,expected",
[
(operator.lt, [True, False, False, False]),
(operator.le, [True, True, False, False]),
(operator.eq, [False, True, False, False]),
(operator.gt, [False, False, False, True]),
],
)
def test_selection_by_datetimelike(self, datetimelike, op, expected):
# GH issue #17965, test for ability to compare datetime64[ns] columns
# to datetimelike
df = DataFrame(
{
"A": [
Timestamp("20120101"),
Timestamp("20130101"),
np.nan,
Timestamp("20130103"),
]
}
)
result = op(df.A, datetimelike)
expected = Series(expected, name="A")
tm.assert_series_equal(result, expected)

@pytest.mark.parametrize(
"start",
[
Expand Down
7 changes: 1 addition & 6 deletions pandas/tests/indexes/period/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ def test_getitem_seconds(self):
# GH7116
# these show deprecations as we are trying
# to slice with non-integer indexers
# FIXME: don't leave commented-out
# with pytest.raises(IndexError):
# idx[v]
continue
Expand Down Expand Up @@ -814,12 +815,6 @@ def test_get_value(self):
result2 = idx2.get_value(input2, p1)
tm.assert_series_equal(result2, expected2)

def test_loc_str(self):
# https://github.com/pandas-dev/pandas/issues/33964
index = period_range(start="2000", periods=20, freq="B")
series = Series(range(20), index=index)
assert series.loc["2000-01-14"] == 9

@pytest.mark.parametrize("freq", ["H", "D"])
def test_get_value_datetime_hourly(self, freq):
# get_loc and get_value should treat datetime objects symmetrically
Expand Down
6 changes: 3 additions & 3 deletions pandas/tests/indexes/period/test_period.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,18 +211,18 @@ def _check_all_fields(self, periodindex):
]

periods = list(periodindex)
s = Series(periodindex)
ser = Series(periodindex)

for field in fields:
field_idx = getattr(periodindex, field)
assert len(periodindex) == len(field_idx)
for x, val in zip(periods, field_idx):
assert getattr(x, field) == val

if len(s) == 0:
if len(ser) == 0:
continue

field_s = getattr(s.dt, field)
field_s = getattr(ser.dt, field)
assert len(periodindex) == len(field_s)
for x, val in zip(periods, field_s):
assert getattr(x, field) == val
Expand Down
11 changes: 0 additions & 11 deletions pandas/tests/indexes/timedeltas/test_ops.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import numpy as np
import pytest

from pandas import (
Series,
TimedeltaIndex,
timedelta_range,
)
Expand Down Expand Up @@ -30,15 +28,6 @@ def test_nonunique_contains(self):
):
assert idx[0] in idx

def test_unknown_attribute(self):
# see gh-9680
tdi = timedelta_range(start=0, periods=10, freq="1s")
ts = Series(np.random.normal(size=10), index=tdi)
assert "foo" not in ts.__dict__.keys()
msg = "'Series' object has no attribute 'foo'"
with pytest.raises(AttributeError, match=msg):
ts.foo

def test_infer_freq(self, freq_sample):
# GH#11018
idx = timedelta_range("1", freq=freq_sample, periods=10)
Expand Down
6 changes: 6 additions & 0 deletions pandas/tests/indexing/test_loc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2941,3 +2941,9 @@ def test_loc_set_multiple_items_in_multiple_new_columns(self):
)

tm.assert_frame_equal(df, expected)

def test_getitem_loc_str_periodindex(self):
# GH#33964
index = pd.period_range(start="2000", periods=20, freq="B")
series = Series(range(20), index=index)
assert series.loc["2000-01-14"] == 9
14 changes: 0 additions & 14 deletions pandas/tests/series/indexing/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,17 +377,3 @@ def test_frozenset_index():
assert s[idx1] == 2
s[idx1] = 3
assert s[idx1] == 3


def test_boolean_index():
# GH18579
s1 = Series([1, 2, 3], index=[4, 5, 6])
s2 = Series([1, 3, 2], index=s1 == 2)
tm.assert_series_equal(Series([1, 3, 2], [False, True, False]), s2)


def test_index_ndim_gt_1_raises():
# GH18579
df = DataFrame([[1, 2], [3, 4], [5, 6]], index=[3, 6, 9])
with pytest.raises(ValueError, match="Index data must be 1-dimensional"):
Series([1, 3, 2], index=df)
9 changes: 9 additions & 0 deletions pandas/tests/series/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,12 @@ def test_inspect_getmembers(self):
ser = Series(dtype=object)
with tm.assert_produces_warning(None):
inspect.getmembers(ser)

def test_unknown_attribute(self):
# GH#9680
tdi = pd.timedelta_range(start=0, periods=10, freq="1s")
ser = Series(np.random.normal(size=10), index=tdi)
assert "foo" not in ser.__dict__.keys()
msg = "'Series' object has no attribute 'foo'"
with pytest.raises(AttributeError, match=msg):
ser.foo
15 changes: 15 additions & 0 deletions pandas/tests/series/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ def test_constructor(self, datetime_series):
with pytest.raises(NotImplementedError, match=msg):
Series(m)

def test_constructor_index_ndim_gt_1_raises(self):
# GH#18579
df = DataFrame([[1, 2], [3, 4], [5, 6]], index=[3, 6, 9])
with pytest.raises(ValueError, match="Index data must be 1-dimensional"):
Series([1, 3, 2], index=df)

@pytest.mark.parametrize("input_class", [list, dict, OrderedDict])
def test_constructor_empty(self, input_class):
with tm.assert_produces_warning(FutureWarning):
Expand Down Expand Up @@ -276,6 +282,15 @@ def test_constructor_list_like(self):
result = Series(obj, index=[0, 1, 2])
tm.assert_series_equal(result, expected)

def test_constructor_boolean_index(self):
# GH#18579
s1 = Series([1, 2, 3], index=[4, 5, 6])

index = s1 == 2
result = Series([1, 3, 2], index=index)
expected = Series([1, 3, 2], index=[False, True, False])
tm.assert_series_equal(result, expected)

@pytest.mark.parametrize("dtype", ["bool", "int32", "int64", "float64"])
def test_constructor_index_dtype(self, dtype):
# GH 17088
Expand Down