Skip to content

CLN: tests.generic #31865

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 27 commits into from
Feb 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
3542366
remove dummy file
jbrockmendel Dec 19, 2019
a183807
CLN
jbrockmendel Dec 19, 2019
58043b3
refactor out TestDescribe
jbrockmendel Dec 19, 2019
c9f3348
refactor out TestDescrbie
jbrockmendel Dec 19, 2019
3a9618d
Merge branch 'master' of https://github.com/pandas-dev/pandas into re…
jbrockmendel Dec 21, 2019
6c4e344
Merge branch 'master' of https://github.com/pandas-dev/pandas into re…
jbrockmendel Dec 23, 2019
9c4f53c
revert
jbrockmendel Dec 23, 2019
18d9531
Merge branch 'master' of https://github.com/pandas-dev/pandas into re…
jbrockmendel Dec 23, 2019
e5fb9d0
Merge branch 'master' of https://github.com/pandas-dev/pandas into re…
jbrockmendel Dec 24, 2019
f228b1a
Merge branch 'master' of https://github.com/pandas-dev/pandas into re…
jbrockmendel Dec 24, 2019
91283da
Merge branch 'master' of https://github.com/pandas-dev/pandas into re…
jbrockmendel Dec 26, 2019
5a69bd0
Merge branch 'master' of https://github.com/pandas-dev/pandas into re…
jbrockmendel Dec 27, 2019
35bc4dc
Merge branch 'master' of https://github.com/pandas-dev/pandas into re…
jbrockmendel Dec 30, 2019
765e144
Merge branch 'master' of https://github.com/pandas-dev/pandas into re…
jbrockmendel Dec 31, 2019
af6a1a3
Merge branch 'master' of https://github.com/pandas-dev/pandas into re…
jbrockmendel Jan 1, 2020
263af27
Merge branch 'master' of https://github.com/pandas-dev/pandas into re…
jbrockmendel Jan 21, 2020
f559bce
Merge branch 'master' of https://github.com/pandas-dev/pandas into re…
jbrockmendel Jan 23, 2020
fb6d245
Merge branch 'master' of https://github.com/pandas-dev/pandas into re…
jbrockmendel Jan 26, 2020
9bf172b
CLN: generic tests
jbrockmendel Feb 7, 2020
1b71e4e
Merge branch 'master' of https://github.com/pandas-dev/pandas into re…
jbrockmendel Feb 7, 2020
fd350db
Merge branch 'master' of https://github.com/pandas-dev/pandas into re…
jbrockmendel Feb 7, 2020
7992cda
Merge branch 'master' of https://github.com/pandas-dev/pandas into re…
jbrockmendel Feb 8, 2020
12b1dea
Merge branch 'master' of https://github.com/pandas-dev/pandas into re…
jbrockmendel Feb 8, 2020
e4422b1
Merge branch 'master' of https://github.com/pandas-dev/pandas into re…
jbrockmendel Feb 9, 2020
da06f10
Merge branch 'master' of https://github.com/pandas-dev/pandas into re…
jbrockmendel Feb 10, 2020
bd83c40
Merge branch 'master' of https://github.com/pandas-dev/pandas into re…
jbrockmendel Feb 11, 2020
6ffad92
merge fixup
jbrockmendel Feb 11, 2020
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
20 changes: 9 additions & 11 deletions pandas/tests/frame/test_block_internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,14 +364,14 @@ def test_pickle(self, float_string_frame, timezone_frame):
def test_consolidate_datetime64(self):
# numpy vstack bug

data = """\
starting,ending,measure
2012-06-21 00:00,2012-06-23 07:00,77
2012-06-23 07:00,2012-06-23 16:30,65
2012-06-23 16:30,2012-06-25 08:00,77
2012-06-25 08:00,2012-06-26 12:00,0
2012-06-26 12:00,2012-06-27 08:00,77
"""
data = (
"starting,ending,measure\n"
"2012-06-21 00:00,2012-06-23 07:00,77\n"
"2012-06-23 07:00,2012-06-23 16:30,65\n"
"2012-06-23 16:30,2012-06-25 08:00,77\n"
"2012-06-25 08:00,2012-06-26 12:00,0\n"
"2012-06-26 12:00,2012-06-27 08:00,77\n"
)
df = pd.read_csv(StringIO(data), parse_dates=[0, 1])

ser_starting = df.starting
Expand All @@ -397,9 +397,6 @@ def test_is_mixed_type(self, float_frame, float_string_frame):
assert float_string_frame._is_mixed_type

def test_get_numeric_data(self):
# TODO(wesm): unused?
intname = np.dtype(np.int_).name # noqa
floatname = np.dtype(np.float_).name # noqa

datetime64name = np.dtype("M8[ns]").name
objectname = np.dtype(np.object_).name
Expand Down Expand Up @@ -581,6 +578,7 @@ def test_get_X_columns(self):
tm.assert_index_equal(df._get_numeric_data().columns, pd.Index(["a", "b", "e"]))

def test_strange_column_corruption_issue(self):
# FIXME: dont leave commented-out
# (wesm) Unclear how exactly this is related to internal matters
df = DataFrame(index=[0, 1])
df[0] = np.nan
Expand Down
3 changes: 0 additions & 3 deletions pandas/tests/frame/test_repr_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,6 @@ def test_repr_unsortable(self, float_frame):
def test_repr_unicode(self):
uval = "\u03c3\u03c3\u03c3\u03c3"

# TODO(wesm): is this supposed to be used?
bval = uval.encode("utf-8") # noqa

df = DataFrame({"A": [uval, uval]})

result = repr(df)
Expand Down
73 changes: 64 additions & 9 deletions pandas/tests/generic/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def finalize(self, other, method=None, **kwargs):

# reset
DataFrame._metadata = _metadata
DataFrame.__finalize__ = _finalize
DataFrame.__finalize__ = _finalize # FIXME: use monkeypatch

def test_set_attribute(self):
# Test for consistent setattr behavior when an attribute and a column
Expand All @@ -174,6 +174,69 @@ def test_set_attribute(self):
assert df.y == 5
tm.assert_series_equal(df["y"], Series([2, 4, 6], name="y"))

def test_deepcopy_empty(self):
# This test covers empty frame copying with non-empty column sets
# as reported in issue GH15370
empty_frame = DataFrame(data=[], index=[], columns=["A"])
empty_frame_copy = deepcopy(empty_frame)

self._compare(empty_frame_copy, empty_frame)


# formerly in Generic but only test DataFrame
class TestDataFrame2:
def test_validate_bool_args(self):
df = DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})
invalid_values = [1, "True", [1, 2, 3], 5.0]

for value in invalid_values:
with pytest.raises(ValueError):
super(DataFrame, df).rename_axis(
mapper={"a": "x", "b": "y"}, axis=1, inplace=value
)

with pytest.raises(ValueError):
super(DataFrame, df).drop("a", axis=1, inplace=value)

with pytest.raises(ValueError):
super(DataFrame, df)._consolidate(inplace=value)

with pytest.raises(ValueError):
super(DataFrame, df).fillna(value=0, inplace=value)

with pytest.raises(ValueError):
super(DataFrame, df).replace(to_replace=1, value=7, inplace=value)

with pytest.raises(ValueError):
super(DataFrame, df).interpolate(inplace=value)

with pytest.raises(ValueError):
super(DataFrame, df)._where(cond=df.a > 2, inplace=value)

with pytest.raises(ValueError):
super(DataFrame, df).mask(cond=df.a > 2, inplace=value)

def test_unexpected_keyword(self):
# GH8597
df = DataFrame(np.random.randn(5, 2), columns=["jim", "joe"])
ca = pd.Categorical([0, 0, 2, 2, 3, np.nan])
ts = df["joe"].copy()
ts[2] = np.nan

with pytest.raises(TypeError, match="unexpected keyword"):
df.drop("joe", axis=1, in_place=True)

with pytest.raises(TypeError, match="unexpected keyword"):
df.reindex([1, 0], inplace=True)

with pytest.raises(TypeError, match="unexpected keyword"):
ca.fillna(0, inplace=True)

with pytest.raises(TypeError, match="unexpected keyword"):
ts.fillna(0, in_place=True)


class TestToXArray:
@pytest.mark.skipif(
not _XARRAY_INSTALLED
or _XARRAY_INSTALLED
Expand Down Expand Up @@ -272,11 +335,3 @@ def test_to_xarray(self):
expected["f"] = expected["f"].astype(object)
expected.columns.name = None
tm.assert_frame_equal(result, expected, check_index_type=False)

def test_deepcopy_empty(self):
# This test covers empty frame copying with non-empty column sets
# as reported in issue GH15370
empty_frame = DataFrame(data=[], index=[], columns=["A"])
empty_frame_copy = deepcopy(empty_frame)

self._compare(empty_frame_copy, empty_frame)
66 changes: 0 additions & 66 deletions pandas/tests/generic/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,23 +103,6 @@ def test_get_numeric_data(self):
# _get_numeric_data is includes _get_bool_data, so can't test for
# non-inclusion

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

def test_nonzero(self):

# GH 4633
Expand Down Expand Up @@ -469,24 +452,6 @@ def test_split_compat(self):
assert len(np.array_split(o, 5)) == 5
assert len(np.array_split(o, 2)) == 2

def test_unexpected_keyword(self): # GH8597
df = DataFrame(np.random.randn(5, 2), columns=["jim", "joe"])
ca = pd.Categorical([0, 0, 2, 2, 3, np.nan])
ts = df["joe"].copy()
ts[2] = np.nan

with pytest.raises(TypeError, match="unexpected keyword"):
df.drop("joe", axis=1, in_place=True)

with pytest.raises(TypeError, match="unexpected keyword"):
df.reindex([1, 0], inplace=True)

with pytest.raises(TypeError, match="unexpected keyword"):
ca.fillna(0, inplace=True)

with pytest.raises(TypeError, match="unexpected keyword"):
ts.fillna(0, in_place=True)

# See gh-12301
def test_stat_unexpected_keyword(self):
obj = self._construct(5)
Expand Down Expand Up @@ -544,37 +509,6 @@ def test_truncate_out_of_bounds(self):
self._compare(big.truncate(before=0, after=3e6), big)
self._compare(big.truncate(before=-1, after=2e6), big)

def test_validate_bool_args(self):
df = DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})
invalid_values = [1, "True", [1, 2, 3], 5.0]

for value in invalid_values:
with pytest.raises(ValueError):
super(DataFrame, df).rename_axis(
mapper={"a": "x", "b": "y"}, axis=1, inplace=value
)

with pytest.raises(ValueError):
super(DataFrame, df).drop("a", axis=1, inplace=value)

with pytest.raises(ValueError):
super(DataFrame, df)._consolidate(inplace=value)

with pytest.raises(ValueError):
super(DataFrame, df).fillna(value=0, inplace=value)

with pytest.raises(ValueError):
super(DataFrame, df).replace(to_replace=1, value=7, inplace=value)

with pytest.raises(ValueError):
super(DataFrame, df).interpolate(inplace=value)

with pytest.raises(ValueError):
super(DataFrame, df)._where(cond=df.a > 2, inplace=value)

with pytest.raises(ValueError):
super(DataFrame, df).mask(cond=df.a > 2, inplace=value)

def test_copy_and_deepcopy(self):
# GH 15444
for shape in [0, 1, 2]:
Expand Down
62 changes: 42 additions & 20 deletions pandas/tests/generic/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,49 @@ def finalize(self, other, method=None, **kwargs):

# reset
Series._metadata = _metadata
Series.__finalize__ = _finalize
Series.__finalize__ = _finalize # FIXME: use monkeypatch

@pytest.mark.parametrize(
"s",
[
Series([np.arange(5)]),
pd.date_range("1/1/2011", periods=24, freq="H"),
pd.Series(range(5), index=pd.date_range("2017", periods=5)),
],
)
@pytest.mark.parametrize("shift_size", [0, 1, 2])
def test_shift_always_copy(self, s, shift_size):
# GH22397
assert s.shift(shift_size) is not s

@pytest.mark.parametrize("move_by_freq", [pd.Timedelta("1D"), pd.Timedelta("1M")])
def test_datetime_shift_always_copy(self, move_by_freq):
# GH22397
s = pd.Series(range(5), index=pd.date_range("2017", periods=5))
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
or _XARRAY_INSTALLED
Expand Down Expand Up @@ -242,22 +283,3 @@ def test_to_xarray(self):
tm.assert_almost_equal(list(result.coords.keys()), ["one", "two"])
assert isinstance(result, DataArray)
tm.assert_series_equal(result.to_series(), s)

@pytest.mark.parametrize(
"s",
[
Series([np.arange(5)]),
pd.date_range("1/1/2011", periods=24, freq="H"),
pd.Series(range(5), index=pd.date_range("2017", periods=5)),
],
)
@pytest.mark.parametrize("shift_size", [0, 1, 2])
def test_shift_always_copy(self, s, shift_size):
# GH22397
assert s.shift(shift_size) is not s

@pytest.mark.parametrize("move_by_freq", [pd.Timedelta("1D"), pd.Timedelta("1M")])
def test_datetime_shift_always_copy(self, move_by_freq):
# GH22397
s = pd.Series(range(5), index=pd.date_range("2017", periods=5))
assert s.shift(freq=move_by_freq) is not s
3 changes: 0 additions & 3 deletions pandas/tests/test_compat.py

This file was deleted.