Skip to content

Commit 27e56f7

Browse files
authored
TST: address TODOs/FIXMES/noqas (pandas-dev#44960)
1 parent 9cd1c6f commit 27e56f7

File tree

14 files changed

+284
-278
lines changed

14 files changed

+284
-278
lines changed

pandas/__init__.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@
2323

2424
try:
2525
from pandas._libs import hashtable as _hashtable, lib as _lib, tslib as _tslib
26-
except ImportError as e: # pragma: no cover
27-
module = e.name
26+
except ImportError as err: # pragma: no cover
27+
module = err.name
2828
raise ImportError(
2929
f"C extension: {module} not built. If you want to import "
3030
"pandas from the source directory, you may need to run "
3131
"'python setup.py build_ext --force' to build the C extensions first."
32-
) from e
32+
) from err
33+
else:
34+
del _tslib, _lib, _hashtable
3335

3436
from pandas._config import (
3537
get_option,

pandas/tests/api/test_api.py

-3
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,9 @@ class TestPDApi(Base):
188188
# private modules in pandas namespace
189189
private_modules = [
190190
"_config",
191-
"_hashtable",
192-
"_lib",
193191
"_libs",
194192
"_is_numpy_dev",
195193
"_testing",
196-
"_tslib",
197194
"_typing",
198195
"_version",
199196
]

pandas/tests/internals/test_internals.py

-3
Original file line numberDiff line numberDiff line change
@@ -494,16 +494,13 @@ def test_copy(self, mgr):
494494

495495
def test_sparse(self):
496496
mgr = create_mgr("a: sparse-1; b: sparse-2")
497-
# what to test here?
498497
assert mgr.as_array().dtype == np.float64
499498

500499
def test_sparse_mixed(self):
501500
mgr = create_mgr("a: sparse-1; b: sparse-2; c: f8")
502501
assert len(mgr.blocks) == 3
503502
assert isinstance(mgr, BlockManager)
504503

505-
# TODO: what to test here?
506-
507504
@pytest.mark.parametrize(
508505
"mgr_string, dtype",
509506
[("c: f4; d: f2", np.float32), ("c: f4; d: f2; e: f8", np.float64)],

pandas/tests/io/formats/test_to_html.py

+52-36
Original file line numberDiff line numberDiff line change
@@ -452,43 +452,59 @@ def test_to_html_invalid_justify(justify):
452452
df.to_html(justify=justify)
453453

454454

455-
def test_to_html_index(datapath):
456-
# TODO: split this test
457-
index = ["foo", "bar", "baz"]
458-
df = DataFrame(
459-
{"A": [1, 2, 3], "B": [1.2, 3.4, 5.6], "C": ["one", "two", np.nan]},
460-
columns=["A", "B", "C"],
461-
index=index,
462-
)
463-
expected_with_index = expected_html(datapath, "index_1")
464-
assert df.to_html() == expected_with_index
465-
466-
expected_without_index = expected_html(datapath, "index_2")
467-
result = df.to_html(index=False)
468-
for i in index:
469-
assert i not in result
470-
assert result == expected_without_index
471-
df.index = Index(["foo", "bar", "baz"], name="idx")
472-
expected_with_index = expected_html(datapath, "index_3")
473-
assert df.to_html() == expected_with_index
474-
assert df.to_html(index=False) == expected_without_index
475-
476-
tuples = [("foo", "car"), ("foo", "bike"), ("bar", "car")]
477-
df.index = MultiIndex.from_tuples(tuples)
478-
479-
expected_with_index = expected_html(datapath, "index_4")
480-
assert df.to_html() == expected_with_index
455+
class TestHTMLIndex:
456+
@pytest.fixture
457+
def df(self):
458+
index = ["foo", "bar", "baz"]
459+
df = DataFrame(
460+
{"A": [1, 2, 3], "B": [1.2, 3.4, 5.6], "C": ["one", "two", np.nan]},
461+
columns=["A", "B", "C"],
462+
index=index,
463+
)
464+
return df
481465

482-
result = df.to_html(index=False)
483-
for i in ["foo", "bar", "car", "bike"]:
484-
assert i not in result
485-
# must be the same result as normal index
486-
assert result == expected_without_index
487-
488-
df.index = MultiIndex.from_tuples(tuples, names=["idx1", "idx2"])
489-
expected_with_index = expected_html(datapath, "index_5")
490-
assert df.to_html() == expected_with_index
491-
assert df.to_html(index=False) == expected_without_index
466+
@pytest.fixture
467+
def expected_without_index(self, datapath):
468+
return expected_html(datapath, "index_2")
469+
470+
def test_to_html_flat_index_without_name(
471+
self, datapath, df, expected_without_index
472+
):
473+
expected_with_index = expected_html(datapath, "index_1")
474+
assert df.to_html() == expected_with_index
475+
476+
result = df.to_html(index=False)
477+
for i in df.index:
478+
assert i not in result
479+
assert result == expected_without_index
480+
481+
def test_to_html_flat_index_with_name(self, datapath, df, expected_without_index):
482+
df.index = Index(["foo", "bar", "baz"], name="idx")
483+
expected_with_index = expected_html(datapath, "index_3")
484+
assert df.to_html() == expected_with_index
485+
assert df.to_html(index=False) == expected_without_index
486+
487+
def test_to_html_multiindex_without_names(
488+
self, datapath, df, expected_without_index
489+
):
490+
tuples = [("foo", "car"), ("foo", "bike"), ("bar", "car")]
491+
df.index = MultiIndex.from_tuples(tuples)
492+
493+
expected_with_index = expected_html(datapath, "index_4")
494+
assert df.to_html() == expected_with_index
495+
496+
result = df.to_html(index=False)
497+
for i in ["foo", "bar", "car", "bike"]:
498+
assert i not in result
499+
# must be the same result as normal index
500+
assert result == expected_without_index
501+
502+
def test_to_html_multiindex_with_names(self, datapath, df, expected_without_index):
503+
tuples = [("foo", "car"), ("foo", "bike"), ("bar", "car")]
504+
df.index = MultiIndex.from_tuples(tuples, names=["idx1", "idx2"])
505+
expected_with_index = expected_html(datapath, "index_5")
506+
assert df.to_html() == expected_with_index
507+
assert df.to_html(index=False) == expected_without_index
492508

493509

494510
@pytest.mark.parametrize("classes", ["sortable draggable", ["sortable", "draggable"]])

pandas/tests/io/json/test_json_table_schema.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -185,14 +185,11 @@ def test_as_json_table_type_date_dtypes(self, date_dtype):
185185
def test_as_json_table_type_timedelta_dtypes(self, td_dtype):
186186
assert as_json_table_type(td_dtype) == "duration"
187187

188-
@pytest.mark.parametrize("str_dtype", [object]) # TODO
188+
@pytest.mark.parametrize("str_dtype", [object]) # TODO(GH#14904) flesh out dtypes?
189189
def test_as_json_table_type_string_dtypes(self, str_dtype):
190190
assert as_json_table_type(str_dtype) == "string"
191191

192192
def test_as_json_table_type_categorical_dtypes(self):
193-
# TODO: I think before is_categorical_dtype(Categorical)
194-
# returned True, but now it's False. Figure out why or
195-
# if it matters
196193
assert as_json_table_type(pd.Categorical(["a"]).dtype) == "any"
197194
assert as_json_table_type(CategoricalDtype()) == "any"
198195

pandas/tests/io/parser/common/test_file_buffer_url.py

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828

2929
@tm.network
3030
def test_url(all_parsers, csv_dir_path):
31-
# TODO: FTP testing
3231
parser = all_parsers
3332
kwargs = {"sep": "\t"}
3433

pandas/tests/io/pytables/test_store.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,8 @@ def test_columns_multiindex_modified(setup_path):
972972
)
973973
cols2load = list("BCD")
974974
cols2load_original = list(cols2load)
975-
df_loaded = read_hdf(path, "df", columns=cols2load) # noqa
975+
# GH#10055 make sure read_hdf call does not alter cols2load inplace
976+
read_hdf(path, "df", columns=cols2load)
976977
assert cols2load_original == cols2load
977978

978979

pandas/tests/io/test_sql.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2128,7 +2128,7 @@ def test_get_engine_auto_error_message(self):
21282128
# Expect different error messages from get_engine(engine="auto")
21292129
# if engines aren't installed vs. are installed but bad version
21302130
pass
2131-
# TODO fill this in when we add more engines
2131+
# TODO(GH#36893) fill this in when we add more engines
21322132

21332133

21342134
class _TestSQLAlchemyConn(_EngineToConnMixin, _TestSQLAlchemy):

pandas/tests/reductions/test_stat_reductions.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,14 @@ def test_dt64_mean(self, tz_naive_fixture, box):
4343
assert obj.mean(skipna=False) is pd.NaT
4444

4545
@pytest.mark.parametrize("box", [Series, pd.Index, PeriodArray])
46-
def test_period_mean(self, box):
46+
@pytest.mark.parametrize("freq", ["S", "H", "D", "W", "B"])
47+
def test_period_mean(self, box, freq):
4748
# GH#24757
4849
dti = pd.date_range("2001-01-01", periods=11)
4950
# shuffle so that we are not just working with monotone-increasing
5051
dti = dti.take([4, 1, 3, 10, 9, 7, 8, 5, 0, 2, 6])
5152

52-
# use hourly frequency to avoid rounding errors in expected results
53-
# TODO: flesh this out with different frequencies
54-
parr = dti._data.to_period("H")
53+
parr = dti._data.to_period(freq)
5554
obj = box(parr)
5655
with pytest.raises(TypeError, match="ambiguous"):
5756
obj.mean()

0 commit comments

Comments
 (0)