Skip to content

Commit 4a8a882

Browse files
jbrockmendelroberthdevries
authored andcommitted
CLN: generic tests (pandas-dev#32256)
1 parent a62c1e9 commit 4a8a882

File tree

3 files changed

+66
-105
lines changed

3 files changed

+66
-105
lines changed

pandas/tests/generic/test_generic.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,10 @@ def test_constructor_compound_dtypes(self):
187187
def f(dtype):
188188
return self._construct(shape=3, value=1, dtype=dtype)
189189

190-
msg = "compound dtypes are not implemented"
191-
f"in the {self._typ.__name__} constructor"
190+
msg = (
191+
"compound dtypes are not implemented "
192+
f"in the {self._typ.__name__} constructor"
193+
)
192194

193195
with pytest.raises(NotImplementedError, match=msg):
194196
f([("A", "datetime64[h]"), ("B", "str"), ("C", "int32")])

pandas/tests/generic/test_series.py

-7
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,6 @@ class TestSeries(Generic):
2424
_typ = Series
2525
_comparator = lambda self, x, y: tm.assert_series_equal(x, y)
2626

27-
def setup_method(self):
28-
self.ts = tm.makeTimeSeries() # Was at top level in test_series
29-
self.ts.name = "ts"
30-
31-
self.series = tm.makeStringSeries()
32-
self.series.name = "series"
33-
3427
def test_rename_mi(self):
3528
s = Series(
3629
[11, 21, 31],

pandas/tests/internals/test_internals.py

+62-96
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,6 @@ def create_mgr(descr, item_shape=None):
203203

204204
class TestBlock:
205205
def setup_method(self, method):
206-
# self.fblock = get_float_ex() # a,c,e
207-
# self.cblock = get_complex_ex() #
208-
# self.oblock = get_obj_ex()
209-
# self.bool_block = get_bool_ex()
210-
# self.int_block = get_int_ex()
211-
212206
self.fblock = create_block("float", [0, 2, 4])
213207
self.cblock = create_block("complex", [7])
214208
self.oblock = create_block("object", [1, 3])
@@ -254,22 +248,11 @@ def test_merge(self):
254248
tm.assert_numpy_array_equal(merged.values[[0, 2]], np.array(avals))
255249
tm.assert_numpy_array_equal(merged.values[[1, 3]], np.array(bvals))
256250

257-
# TODO: merge with mixed type?
258-
259251
def test_copy(self):
260252
cop = self.fblock.copy()
261253
assert cop is not self.fblock
262254
assert_block_equal(self.fblock, cop)
263255

264-
def test_reindex_index(self):
265-
pass
266-
267-
def test_reindex_cast(self):
268-
pass
269-
270-
def test_insert(self):
271-
pass
272-
273256
def test_delete(self):
274257
newb = self.fblock.copy()
275258
newb.delete(0)
@@ -300,39 +283,7 @@ def test_delete(self):
300283
newb.delete(3)
301284

302285

303-
class TestDatetimeBlock:
304-
def test_can_hold_element(self):
305-
block = create_block("datetime", [0])
306-
307-
# We will check that block._can_hold_element iff arr.__setitem__ works
308-
arr = pd.array(block.values.ravel())
309-
310-
# coerce None
311-
assert block._can_hold_element(None)
312-
arr[0] = None
313-
assert arr[0] is pd.NaT
314-
315-
# coerce different types of datetime objects
316-
vals = [np.datetime64("2010-10-10"), datetime(2010, 10, 10)]
317-
for val in vals:
318-
assert block._can_hold_element(val)
319-
arr[0] = val
320-
321-
val = date(2010, 10, 10)
322-
assert not block._can_hold_element(val)
323-
324-
msg = (
325-
"'value' should be a 'Timestamp', 'NaT', "
326-
"or array of those. Got 'date' instead."
327-
)
328-
with pytest.raises(TypeError, match=msg):
329-
arr[0] = val
330-
331-
332286
class TestBlockManager:
333-
def test_constructor_corner(self):
334-
pass
335-
336287
def test_attrs(self):
337288
mgr = create_mgr("a,b,c: f8-1; d,e,f: f8-2")
338289
assert mgr.nblocks == 2
@@ -441,18 +392,6 @@ def test_set_change_dtype(self, mgr):
441392
mgr2.set("quux", tm.randn(N))
442393
assert mgr2.get("quux").dtype == np.float_
443394

444-
def test_set_change_dtype_slice(self): # GH8850
445-
cols = MultiIndex.from_tuples([("1st", "a"), ("2nd", "b"), ("3rd", "c")])
446-
df = DataFrame([[1.0, 2, 3], [4.0, 5, 6]], columns=cols)
447-
df["2nd"] = df["2nd"] * 2.0
448-
449-
blocks = df._to_dict_of_blocks()
450-
assert sorted(blocks.keys()) == ["float64", "int64"]
451-
tm.assert_frame_equal(
452-
blocks["float64"], DataFrame([[1.0, 4.0], [4.0, 10.0]], columns=cols[:2])
453-
)
454-
tm.assert_frame_equal(blocks["int64"], DataFrame([[3], [6]], columns=cols[2:]))
455-
456395
def test_copy(self, mgr):
457396
cp = mgr.copy(deep=False)
458397
for blk, cp_blk in zip(mgr.blocks, cp.blocks):
@@ -486,7 +425,7 @@ def test_sparse_mixed(self):
486425
assert len(mgr.blocks) == 3
487426
assert isinstance(mgr, BlockManager)
488427

489-
# what to test here?
428+
# TODO: what to test here?
490429

491430
def test_as_array_float(self):
492431
mgr = create_mgr("c: f4; d: f2; e: f8")
@@ -650,22 +589,6 @@ def test_interleave(self):
650589
mgr = create_mgr("a: M8[ns]; b: m8[ns]")
651590
assert mgr.as_array().dtype == "object"
652591

653-
def test_interleave_non_unique_cols(self):
654-
df = DataFrame(
655-
[[pd.Timestamp("20130101"), 3.5], [pd.Timestamp("20130102"), 4.5]],
656-
columns=["x", "x"],
657-
index=[1, 2],
658-
)
659-
660-
df_unique = df.copy()
661-
df_unique.columns = ["x", "y"]
662-
assert df_unique.values.shape == df.values.shape
663-
tm.assert_numpy_array_equal(df_unique.values[0], df.values[0])
664-
tm.assert_numpy_array_equal(df_unique.values[1], df.values[1])
665-
666-
def test_consolidate(self):
667-
pass
668-
669592
def test_consolidate_ordering_issues(self, mgr):
670593
mgr.set("f", tm.randn(N))
671594
mgr.set("d", tm.randn(N))
@@ -683,10 +606,6 @@ def test_consolidate_ordering_issues(self, mgr):
683606
cons.blocks[0].mgr_locs.as_array, np.arange(len(cons.items), dtype=np.int64)
684607
)
685608

686-
def test_reindex_index(self):
687-
# TODO: should this be pytest.skip?
688-
pass
689-
690609
def test_reindex_items(self):
691610
# mgr is not consolidated, f8 & f8-2 blocks
692611
mgr = create_mgr("a: f8; b: i8; c: f8; d: i8; e: f8; f: bool; g: f8-2")
@@ -767,13 +686,6 @@ def test_get_bool_data(self):
767686
def test_unicode_repr_doesnt_raise(self):
768687
repr(create_mgr("b,\u05d0: object"))
769688

770-
def test_missing_unicode_key(self):
771-
df = DataFrame({"a": [1]})
772-
try:
773-
df.loc[:, "\u05d0"] # should not raise UnicodeEncodeError
774-
except KeyError:
775-
pass # this is the expected exception
776-
777689
def test_equals(self):
778690
# unique items
779691
bm1 = create_mgr("a,b,c: i8-1; d,e,f: i8-2")
@@ -843,8 +755,6 @@ class TestIndexing:
843755
create_mgr("a,b: f8; c,d: i8; e,f: f8", item_shape=(N, N)),
844756
]
845757

846-
# MANAGERS = [MANAGERS[6]]
847-
848758
@pytest.mark.parametrize("mgr", MANAGERS)
849759
def test_get_slice(self, mgr):
850760
def assert_slice_ok(mgr, axis, slobj):
@@ -994,11 +904,6 @@ def assert_reindex_indexer_is_ok(mgr, axis, new_labels, indexer, fill_value):
994904
mgr, ax, pd.Index(["foo", "bar", "baz"]), [0, 1, 2], fill_value,
995905
)
996906

997-
# test_get_slice(slice_like, axis)
998-
# take(indexer, axis)
999-
# reindex_axis(new_labels, axis)
1000-
# reindex_indexer(new_labels, indexer, axis)
1001-
1002907

1003908
class TestBlockPlacement:
1004909
def test_slice_len(self):
@@ -1151,6 +1056,33 @@ def any(self, axis=None):
11511056

11521057

11531058
class TestCanHoldElement:
1059+
def test_datetime_block_can_hold_element(self):
1060+
block = create_block("datetime", [0])
1061+
1062+
# We will check that block._can_hold_element iff arr.__setitem__ works
1063+
arr = pd.array(block.values.ravel())
1064+
1065+
# coerce None
1066+
assert block._can_hold_element(None)
1067+
arr[0] = None
1068+
assert arr[0] is pd.NaT
1069+
1070+
# coerce different types of datetime objects
1071+
vals = [np.datetime64("2010-10-10"), datetime(2010, 10, 10)]
1072+
for val in vals:
1073+
assert block._can_hold_element(val)
1074+
arr[0] = val
1075+
1076+
val = date(2010, 10, 10)
1077+
assert not block._can_hold_element(val)
1078+
1079+
msg = (
1080+
"'value' should be a 'Timestamp', 'NaT', "
1081+
"or array of those. Got 'date' instead."
1082+
)
1083+
with pytest.raises(TypeError, match=msg):
1084+
arr[0] = val
1085+
11541086
@pytest.mark.parametrize(
11551087
"value, dtype",
11561088
[
@@ -1280,3 +1212,37 @@ def test_dataframe_not_equal():
12801212
df1 = pd.DataFrame({"a": [1, 2], "b": ["s", "d"]})
12811213
df2 = pd.DataFrame({"a": ["s", "d"], "b": [1, 2]})
12821214
assert df1.equals(df2) is False
1215+
1216+
1217+
def test_missing_unicode_key():
1218+
df = DataFrame({"a": [1]})
1219+
with pytest.raises(KeyError, match="\u05d0"):
1220+
df.loc[:, "\u05d0"] # should not raise UnicodeEncodeError
1221+
1222+
1223+
def test_set_change_dtype_slice():
1224+
# GH#8850
1225+
cols = MultiIndex.from_tuples([("1st", "a"), ("2nd", "b"), ("3rd", "c")])
1226+
df = DataFrame([[1.0, 2, 3], [4.0, 5, 6]], columns=cols)
1227+
df["2nd"] = df["2nd"] * 2.0
1228+
1229+
blocks = df._to_dict_of_blocks()
1230+
assert sorted(blocks.keys()) == ["float64", "int64"]
1231+
tm.assert_frame_equal(
1232+
blocks["float64"], DataFrame([[1.0, 4.0], [4.0, 10.0]], columns=cols[:2])
1233+
)
1234+
tm.assert_frame_equal(blocks["int64"], DataFrame([[3], [6]], columns=cols[2:]))
1235+
1236+
1237+
def test_interleave_non_unique_cols():
1238+
df = DataFrame(
1239+
[[pd.Timestamp("20130101"), 3.5], [pd.Timestamp("20130102"), 4.5]],
1240+
columns=["x", "x"],
1241+
index=[1, 2],
1242+
)
1243+
1244+
df_unique = df.copy()
1245+
df_unique.columns = ["x", "y"]
1246+
assert df_unique.values.shape == df.values.shape
1247+
tm.assert_numpy_array_equal(df_unique.values[0], df.values[0])
1248+
tm.assert_numpy_array_equal(df_unique.values[1], df.values[1])

0 commit comments

Comments
 (0)