Skip to content

Commit 50ebb24

Browse files
authored
CLN: tests.generic (#31865)
1 parent 9d66896 commit 50ebb24

File tree

6 files changed

+115
-112
lines changed

6 files changed

+115
-112
lines changed

pandas/tests/frame/test_block_internals.py

+9-11
Original file line numberDiff line numberDiff line change
@@ -364,14 +364,14 @@ def test_pickle(self, float_string_frame, timezone_frame):
364364
def test_consolidate_datetime64(self):
365365
# numpy vstack bug
366366

367-
data = """\
368-
starting,ending,measure
369-
2012-06-21 00:00,2012-06-23 07:00,77
370-
2012-06-23 07:00,2012-06-23 16:30,65
371-
2012-06-23 16:30,2012-06-25 08:00,77
372-
2012-06-25 08:00,2012-06-26 12:00,0
373-
2012-06-26 12:00,2012-06-27 08:00,77
374-
"""
367+
data = (
368+
"starting,ending,measure\n"
369+
"2012-06-21 00:00,2012-06-23 07:00,77\n"
370+
"2012-06-23 07:00,2012-06-23 16:30,65\n"
371+
"2012-06-23 16:30,2012-06-25 08:00,77\n"
372+
"2012-06-25 08:00,2012-06-26 12:00,0\n"
373+
"2012-06-26 12:00,2012-06-27 08:00,77\n"
374+
)
375375
df = pd.read_csv(StringIO(data), parse_dates=[0, 1])
376376

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

399399
def test_get_numeric_data(self):
400-
# TODO(wesm): unused?
401-
intname = np.dtype(np.int_).name # noqa
402-
floatname = np.dtype(np.float_).name # noqa
403400

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

583580
def test_strange_column_corruption_issue(self):
581+
# FIXME: dont leave commented-out
584582
# (wesm) Unclear how exactly this is related to internal matters
585583
df = DataFrame(index=[0, 1])
586584
df[0] = np.nan

pandas/tests/frame/test_repr_info.py

-3
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,6 @@ def test_repr_unsortable(self, float_frame):
129129
def test_repr_unicode(self):
130130
uval = "\u03c3\u03c3\u03c3\u03c3"
131131

132-
# TODO(wesm): is this supposed to be used?
133-
bval = uval.encode("utf-8") # noqa
134-
135132
df = DataFrame({"A": [uval, uval]})
136133

137134
result = repr(df)

pandas/tests/generic/test_frame.py

+64-9
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def finalize(self, other, method=None, **kwargs):
160160

161161
# reset
162162
DataFrame._metadata = _metadata
163-
DataFrame.__finalize__ = _finalize
163+
DataFrame.__finalize__ = _finalize # FIXME: use monkeypatch
164164

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

177+
def test_deepcopy_empty(self):
178+
# This test covers empty frame copying with non-empty column sets
179+
# as reported in issue GH15370
180+
empty_frame = DataFrame(data=[], index=[], columns=["A"])
181+
empty_frame_copy = deepcopy(empty_frame)
182+
183+
self._compare(empty_frame_copy, empty_frame)
184+
185+
186+
# formerly in Generic but only test DataFrame
187+
class TestDataFrame2:
188+
def test_validate_bool_args(self):
189+
df = DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})
190+
invalid_values = [1, "True", [1, 2, 3], 5.0]
191+
192+
for value in invalid_values:
193+
with pytest.raises(ValueError):
194+
super(DataFrame, df).rename_axis(
195+
mapper={"a": "x", "b": "y"}, axis=1, inplace=value
196+
)
197+
198+
with pytest.raises(ValueError):
199+
super(DataFrame, df).drop("a", axis=1, inplace=value)
200+
201+
with pytest.raises(ValueError):
202+
super(DataFrame, df)._consolidate(inplace=value)
203+
204+
with pytest.raises(ValueError):
205+
super(DataFrame, df).fillna(value=0, inplace=value)
206+
207+
with pytest.raises(ValueError):
208+
super(DataFrame, df).replace(to_replace=1, value=7, inplace=value)
209+
210+
with pytest.raises(ValueError):
211+
super(DataFrame, df).interpolate(inplace=value)
212+
213+
with pytest.raises(ValueError):
214+
super(DataFrame, df)._where(cond=df.a > 2, inplace=value)
215+
216+
with pytest.raises(ValueError):
217+
super(DataFrame, df).mask(cond=df.a > 2, inplace=value)
218+
219+
def test_unexpected_keyword(self):
220+
# GH8597
221+
df = DataFrame(np.random.randn(5, 2), columns=["jim", "joe"])
222+
ca = pd.Categorical([0, 0, 2, 2, 3, np.nan])
223+
ts = df["joe"].copy()
224+
ts[2] = np.nan
225+
226+
with pytest.raises(TypeError, match="unexpected keyword"):
227+
df.drop("joe", axis=1, in_place=True)
228+
229+
with pytest.raises(TypeError, match="unexpected keyword"):
230+
df.reindex([1, 0], inplace=True)
231+
232+
with pytest.raises(TypeError, match="unexpected keyword"):
233+
ca.fillna(0, inplace=True)
234+
235+
with pytest.raises(TypeError, match="unexpected keyword"):
236+
ts.fillna(0, in_place=True)
237+
238+
239+
class TestToXArray:
177240
@pytest.mark.skipif(
178241
not _XARRAY_INSTALLED
179242
or _XARRAY_INSTALLED
@@ -272,11 +335,3 @@ def test_to_xarray(self):
272335
expected["f"] = expected["f"].astype(object)
273336
expected.columns.name = None
274337
tm.assert_frame_equal(result, expected, check_index_type=False)
275-
276-
def test_deepcopy_empty(self):
277-
# This test covers empty frame copying with non-empty column sets
278-
# as reported in issue GH15370
279-
empty_frame = DataFrame(data=[], index=[], columns=["A"])
280-
empty_frame_copy = deepcopy(empty_frame)
281-
282-
self._compare(empty_frame_copy, empty_frame)

pandas/tests/generic/test_generic.py

-66
Original file line numberDiff line numberDiff line change
@@ -103,23 +103,6 @@ def test_get_numeric_data(self):
103103
# _get_numeric_data is includes _get_bool_data, so can't test for
104104
# non-inclusion
105105

106-
def test_get_default(self):
107-
108-
# GH 7725
109-
d0 = "a", "b", "c", "d"
110-
d1 = np.arange(4, dtype="int64")
111-
others = "e", 10
112-
113-
for data, index in ((d0, d1), (d1, d0)):
114-
s = Series(data, index=index)
115-
for i, d in zip(index, data):
116-
assert s.get(i) == d
117-
assert s.get(i, d) == d
118-
assert s.get(i, "z") == d
119-
for other in others:
120-
assert s.get(other, "z") == "z"
121-
assert s.get(other, other) == other
122-
123106
def test_nonzero(self):
124107

125108
# GH 4633
@@ -469,24 +452,6 @@ def test_split_compat(self):
469452
assert len(np.array_split(o, 5)) == 5
470453
assert len(np.array_split(o, 2)) == 2
471454

472-
def test_unexpected_keyword(self): # GH8597
473-
df = DataFrame(np.random.randn(5, 2), columns=["jim", "joe"])
474-
ca = pd.Categorical([0, 0, 2, 2, 3, np.nan])
475-
ts = df["joe"].copy()
476-
ts[2] = np.nan
477-
478-
with pytest.raises(TypeError, match="unexpected keyword"):
479-
df.drop("joe", axis=1, in_place=True)
480-
481-
with pytest.raises(TypeError, match="unexpected keyword"):
482-
df.reindex([1, 0], inplace=True)
483-
484-
with pytest.raises(TypeError, match="unexpected keyword"):
485-
ca.fillna(0, inplace=True)
486-
487-
with pytest.raises(TypeError, match="unexpected keyword"):
488-
ts.fillna(0, in_place=True)
489-
490455
# See gh-12301
491456
def test_stat_unexpected_keyword(self):
492457
obj = self._construct(5)
@@ -544,37 +509,6 @@ def test_truncate_out_of_bounds(self):
544509
self._compare(big.truncate(before=0, after=3e6), big)
545510
self._compare(big.truncate(before=-1, after=2e6), big)
546511

547-
def test_validate_bool_args(self):
548-
df = DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})
549-
invalid_values = [1, "True", [1, 2, 3], 5.0]
550-
551-
for value in invalid_values:
552-
with pytest.raises(ValueError):
553-
super(DataFrame, df).rename_axis(
554-
mapper={"a": "x", "b": "y"}, axis=1, inplace=value
555-
)
556-
557-
with pytest.raises(ValueError):
558-
super(DataFrame, df).drop("a", axis=1, inplace=value)
559-
560-
with pytest.raises(ValueError):
561-
super(DataFrame, df)._consolidate(inplace=value)
562-
563-
with pytest.raises(ValueError):
564-
super(DataFrame, df).fillna(value=0, inplace=value)
565-
566-
with pytest.raises(ValueError):
567-
super(DataFrame, df).replace(to_replace=1, value=7, inplace=value)
568-
569-
with pytest.raises(ValueError):
570-
super(DataFrame, df).interpolate(inplace=value)
571-
572-
with pytest.raises(ValueError):
573-
super(DataFrame, df)._where(cond=df.a > 2, inplace=value)
574-
575-
with pytest.raises(ValueError):
576-
super(DataFrame, df).mask(cond=df.a > 2, inplace=value)
577-
578512
def test_copy_and_deepcopy(self):
579513
# GH 15444
580514
for shape in [0, 1, 2]:

pandas/tests/generic/test_series.py

+42-20
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,49 @@ def finalize(self, other, method=None, **kwargs):
181181

182182
# reset
183183
Series._metadata = _metadata
184-
Series.__finalize__ = _finalize
184+
Series.__finalize__ = _finalize # FIXME: use monkeypatch
185185

186+
@pytest.mark.parametrize(
187+
"s",
188+
[
189+
Series([np.arange(5)]),
190+
pd.date_range("1/1/2011", periods=24, freq="H"),
191+
pd.Series(range(5), index=pd.date_range("2017", periods=5)),
192+
],
193+
)
194+
@pytest.mark.parametrize("shift_size", [0, 1, 2])
195+
def test_shift_always_copy(self, s, shift_size):
196+
# GH22397
197+
assert s.shift(shift_size) is not s
198+
199+
@pytest.mark.parametrize("move_by_freq", [pd.Timedelta("1D"), pd.Timedelta("1M")])
200+
def test_datetime_shift_always_copy(self, move_by_freq):
201+
# GH22397
202+
s = pd.Series(range(5), index=pd.date_range("2017", periods=5))
203+
assert s.shift(freq=move_by_freq) is not s
204+
205+
206+
class TestSeries2:
207+
# moved from Generic
208+
def test_get_default(self):
209+
210+
# GH#7725
211+
d0 = ["a", "b", "c", "d"]
212+
d1 = np.arange(4, dtype="int64")
213+
others = ["e", 10]
214+
215+
for data, index in ((d0, d1), (d1, d0)):
216+
s = Series(data, index=index)
217+
for i, d in zip(index, data):
218+
assert s.get(i) == d
219+
assert s.get(i, d) == d
220+
assert s.get(i, "z") == d
221+
for other in others:
222+
assert s.get(other, "z") == "z"
223+
assert s.get(other, other) == other
224+
225+
226+
class TestToXArray:
186227
@pytest.mark.skipif(
187228
not _XARRAY_INSTALLED
188229
or _XARRAY_INSTALLED
@@ -242,22 +283,3 @@ def test_to_xarray(self):
242283
tm.assert_almost_equal(list(result.coords.keys()), ["one", "two"])
243284
assert isinstance(result, DataArray)
244285
tm.assert_series_equal(result.to_series(), s)
245-
246-
@pytest.mark.parametrize(
247-
"s",
248-
[
249-
Series([np.arange(5)]),
250-
pd.date_range("1/1/2011", periods=24, freq="H"),
251-
pd.Series(range(5), index=pd.date_range("2017", periods=5)),
252-
],
253-
)
254-
@pytest.mark.parametrize("shift_size", [0, 1, 2])
255-
def test_shift_always_copy(self, s, shift_size):
256-
# GH22397
257-
assert s.shift(shift_size) is not s
258-
259-
@pytest.mark.parametrize("move_by_freq", [pd.Timedelta("1D"), pd.Timedelta("1M")])
260-
def test_datetime_shift_always_copy(self, move_by_freq):
261-
# GH22397
262-
s = pd.Series(range(5), index=pd.date_range("2017", periods=5))
263-
assert s.shift(freq=move_by_freq) is not s

pandas/tests/test_compat.py

-3
This file was deleted.

0 commit comments

Comments
 (0)