diff --git a/pandas/tests/io/formats/data/datetime64_hourformatter.html b/pandas/tests/io/formats/data/datetime64_hourformatter.html
new file mode 100644
index 00000000000000..c92b7218eba767
--- /dev/null
+++ b/pandas/tests/io/formats/data/datetime64_hourformatter.html
@@ -0,0 +1,18 @@
+
+
+
+ |
+ hod |
+
+
+
+
+ 0 |
+ 10:10 |
+
+
+ 1 |
+ 12:12 |
+
+
+
diff --git a/pandas/tests/io/formats/data/datetime64_monthformatter.html b/pandas/tests/io/formats/data/datetime64_monthformatter.html
new file mode 100644
index 00000000000000..589c8fba858a5f
--- /dev/null
+++ b/pandas/tests/io/formats/data/datetime64_monthformatter.html
@@ -0,0 +1,18 @@
+
+
+
+ |
+ months |
+
+
+
+
+ 0 |
+ 2016-01 |
+
+
+ 1 |
+ 2016-02 |
+
+
+
diff --git a/pandas/tests/io/formats/data/escape_disabled.html b/pandas/tests/io/formats/data/escape_disabled.html
new file mode 100644
index 00000000000000..260a04d26108b8
--- /dev/null
+++ b/pandas/tests/io/formats/data/escape_disabled.html
@@ -0,0 +1,21 @@
+
+
+
+ |
+ co
+ co>l2 |
+ |
+
+
+
+ str
+ bold |
+ bold |
+ |
+
+ stri>ng2 & |
+ bold |
+ bold |
+
+
+
diff --git a/pandas/tests/io/formats/data/escaped.html b/pandas/tests/io/formats/data/escaped.html
new file mode 100644
index 00000000000000..d68bdd3df79c48
--- /dev/null
+++ b/pandas/tests/io/formats/data/escaped.html
@@ -0,0 +1,21 @@
+
+
+
+ |
+ co<l1 |
+ co>l2 |
+
+
+
+
+ str<ing1 & |
+ <type 'str'> |
+ <type 'str'> |
+
+
+ stri>ng2 & |
+ <type 'str'> |
+ <type 'str'> |
+
+
+
diff --git a/pandas/tests/io/formats/data/gh12031_expected_output.html b/pandas/tests/io/formats/data/gh12031_expected_output.html
new file mode 100644
index 00000000000000..896e154a2b3242
--- /dev/null
+++ b/pandas/tests/io/formats/data/gh12031_expected_output.html
@@ -0,0 +1,22 @@
+
+
+
+ |
+ A |
+
+
+
+
+ 0 |
+ 6,0 |
+
+
+ 1 |
+ 3,1 |
+
+
+ 2 |
+ 2,2 |
+
+
+
diff --git a/pandas/tests/io/formats/data/gh14882_expected_output_1.html b/pandas/tests/io/formats/data/gh14882_expected_output_1.html
new file mode 100644
index 00000000000000..4cfd8785de8257
--- /dev/null
+++ b/pandas/tests/io/formats/data/gh14882_expected_output_1.html
@@ -0,0 +1,274 @@
+
+
+
+ |
+ |
+ |
+ n |
+
+
+ a |
+ b |
+ c |
+ |
+
+
+
+
+ 100 |
+ 10 |
+ 1 |
+ 0 |
+
+
+ 2 |
+ 1 |
+
+
+ 3 |
+ 2 |
+
+
+ 4 |
+ 3 |
+
+
+ 5 |
+ 4 |
+
+
+ 6 |
+ 5 |
+
+
+ 7 |
+ 6 |
+
+
+ 20 |
+ 1 |
+ 7 |
+
+
+ 2 |
+ 8 |
+
+
+ 3 |
+ 9 |
+
+
+ 4 |
+ 10 |
+
+
+ 5 |
+ 11 |
+
+
+ 6 |
+ 12 |
+
+
+ 7 |
+ 13 |
+
+
+ 30 |
+ 1 |
+ 14 |
+
+
+ 2 |
+ 15 |
+
+
+ 3 |
+ 16 |
+
+
+ 4 |
+ 17 |
+
+
+ 5 |
+ 18 |
+
+
+ 6 |
+ 19 |
+
+
+ 7 |
+ 20 |
+
+
+ 200 |
+ 10 |
+ 1 |
+ 21 |
+
+
+ 2 |
+ 22 |
+
+
+ 3 |
+ 23 |
+
+
+ 4 |
+ 24 |
+
+
+ 5 |
+ 25 |
+
+
+ 6 |
+ 26 |
+
+
+ 7 |
+ 27 |
+
+
+ 20 |
+ 1 |
+ 28 |
+
+
+ 2 |
+ 29 |
+
+
+ ... |
+ ... |
+
+
+ 6 |
+ 33 |
+
+
+ 7 |
+ 34 |
+
+
+ 30 |
+ 1 |
+ 35 |
+
+
+ 2 |
+ 36 |
+
+
+ 3 |
+ 37 |
+
+
+ 4 |
+ 38 |
+
+
+ 5 |
+ 39 |
+
+
+ 6 |
+ 40 |
+
+
+ 7 |
+ 41 |
+
+
+ 300 |
+ 10 |
+ 1 |
+ 42 |
+
+
+ 2 |
+ 43 |
+
+
+ 3 |
+ 44 |
+
+
+ 4 |
+ 45 |
+
+
+ 5 |
+ 46 |
+
+
+ 6 |
+ 47 |
+
+
+ 7 |
+ 48 |
+
+
+ 20 |
+ 1 |
+ 49 |
+
+
+ 2 |
+ 50 |
+
+
+ 3 |
+ 51 |
+
+
+ 4 |
+ 52 |
+
+
+ 5 |
+ 53 |
+
+
+ 6 |
+ 54 |
+
+
+ 7 |
+ 55 |
+
+
+ 30 |
+ 1 |
+ 56 |
+
+
+ 2 |
+ 57 |
+
+
+ 3 |
+ 58 |
+
+
+ 4 |
+ 59 |
+
+
+ 5 |
+ 60 |
+
+
+ 6 |
+ 61 |
+
+
+ 7 |
+ 62 |
+
+
+
diff --git a/pandas/tests/io/formats/data/gh14882_expected_output_2.html b/pandas/tests/io/formats/data/gh14882_expected_output_2.html
new file mode 100644
index 00000000000000..d4e7fd9bd81350
--- /dev/null
+++ b/pandas/tests/io/formats/data/gh14882_expected_output_2.html
@@ -0,0 +1,258 @@
+
+
+
+ |
+ |
+ |
+ n |
+
+
+ a |
+ b |
+ c |
+ |
+
+
+
+
+ 100 |
+ 10 |
+ 1 |
+ 0 |
+
+
+ 2 |
+ 1 |
+
+
+ 3 |
+ 2 |
+
+
+ 4 |
+ 3 |
+
+
+ 5 |
+ 4 |
+
+
+ 6 |
+ 5 |
+
+
+ 7 |
+ 6 |
+
+
+ 20 |
+ 1 |
+ 7 |
+
+
+ 2 |
+ 8 |
+
+
+ 3 |
+ 9 |
+
+
+ 4 |
+ 10 |
+
+
+ 5 |
+ 11 |
+
+
+ 6 |
+ 12 |
+
+
+ 7 |
+ 13 |
+
+
+ 30 |
+ 1 |
+ 14 |
+
+
+ 2 |
+ 15 |
+
+
+ 3 |
+ 16 |
+
+
+ 4 |
+ 17 |
+
+
+ 5 |
+ 18 |
+
+
+ 6 |
+ 19 |
+
+
+ 7 |
+ 20 |
+
+
+ 200 |
+ 10 |
+ 1 |
+ 21 |
+
+
+ 2 |
+ 22 |
+
+
+ 3 |
+ 23 |
+
+
+ 4 |
+ 24 |
+
+
+ 5 |
+ 25 |
+
+
+ 6 |
+ 26 |
+
+
+ 7 |
+ 27 |
+
+
+ ... |
+ ... |
+ ... |
+
+
+ 30 |
+ 1 |
+ 35 |
+
+
+ 2 |
+ 36 |
+
+
+ 3 |
+ 37 |
+
+
+ 4 |
+ 38 |
+
+
+ 5 |
+ 39 |
+
+
+ 6 |
+ 40 |
+
+
+ 7 |
+ 41 |
+
+
+ 300 |
+ 10 |
+ 1 |
+ 42 |
+
+
+ 2 |
+ 43 |
+
+
+ 3 |
+ 44 |
+
+
+ 4 |
+ 45 |
+
+
+ 5 |
+ 46 |
+
+
+ 6 |
+ 47 |
+
+
+ 7 |
+ 48 |
+
+
+ 20 |
+ 1 |
+ 49 |
+
+
+ 2 |
+ 50 |
+
+
+ 3 |
+ 51 |
+
+
+ 4 |
+ 52 |
+
+
+ 5 |
+ 53 |
+
+
+ 6 |
+ 54 |
+
+
+ 7 |
+ 55 |
+
+
+ 30 |
+ 1 |
+ 56 |
+
+
+ 2 |
+ 57 |
+
+
+ 3 |
+ 58 |
+
+
+ 4 |
+ 59 |
+
+
+ 5 |
+ 60 |
+
+
+ 6 |
+ 61 |
+
+
+ 7 |
+ 62 |
+
+
+
diff --git a/pandas/tests/io/formats/data/gh14998_expected_output.html b/pandas/tests/io/formats/data/gh14998_expected_output.html
new file mode 100644
index 00000000000000..62b96493a8ecd3
--- /dev/null
+++ b/pandas/tests/io/formats/data/gh14998_expected_output.html
@@ -0,0 +1,12 @@
+
+
+
+ A |
+
+
+
+
+ 1 |
+
+
+
diff --git a/pandas/tests/io/formats/data/gh6131_expected_output.html b/pandas/tests/io/formats/data/gh6131_expected_output.html
new file mode 100644
index 00000000000000..cb3a3363ff0163
--- /dev/null
+++ b/pandas/tests/io/formats/data/gh6131_expected_output.html
@@ -0,0 +1,46 @@
+
+
+
+ |
+ |
+ d |
+
+
+ |
+ a |
+ aa |
+ ... |
+ ac |
+
+
+ b |
+ c |
+ |
+ |
+ |
+
+
+
+
+ ba |
+ ca |
+ 1.0 |
+ ... |
+ NaN |
+
+
+ bb |
+ cb |
+ NaN |
+ ... |
+ NaN |
+
+
+ bc |
+ cc |
+ NaN |
+ ... |
+ 3.0 |
+
+
+
diff --git a/pandas/tests/io/formats/data/gh8452_expected_output.html b/pandas/tests/io/formats/data/gh8452_expected_output.html
new file mode 100644
index 00000000000000..81ce397a201e00
--- /dev/null
+++ b/pandas/tests/io/formats/data/gh8452_expected_output.html
@@ -0,0 +1,28 @@
+
+
+
+ a |
+ b |
+
+
+ c |
+ d |
+ c |
+ d |
+
+
+
+
+ 0 |
+ 3 |
+ 5 |
+ 3 |
+
+
+ 1 |
+ 4 |
+ 6 |
+ 4 |
+
+
+
diff --git a/pandas/tests/io/formats/data/index_1.html b/pandas/tests/io/formats/data/index_1.html
new file mode 100644
index 00000000000000..41221865a7cb7a
--- /dev/null
+++ b/pandas/tests/io/formats/data/index_1.html
@@ -0,0 +1,30 @@
+
+
+
+ |
+ A |
+ B |
+ C |
+
+
+
+
+ foo |
+ 1 |
+ 1.2 |
+ one |
+
+
+ bar |
+ 2 |
+ 3.4 |
+ two |
+
+
+ baz |
+ 3 |
+ 5.6 |
+ NaN |
+
+
+
diff --git a/pandas/tests/io/formats/data/index_2.html b/pandas/tests/io/formats/data/index_2.html
new file mode 100644
index 00000000000000..a86ba80a69bb1d
--- /dev/null
+++ b/pandas/tests/io/formats/data/index_2.html
@@ -0,0 +1,26 @@
+
+
+
+ A |
+ B |
+ C |
+
+
+
+
+ 1 |
+ 1.2 |
+ one |
+
+
+ 2 |
+ 3.4 |
+ two |
+
+
+ 3 |
+ 5.6 |
+ NaN |
+
+
+
diff --git a/pandas/tests/io/formats/data/index_3.html b/pandas/tests/io/formats/data/index_3.html
new file mode 100644
index 00000000000000..02edba4961bc78
--- /dev/null
+++ b/pandas/tests/io/formats/data/index_3.html
@@ -0,0 +1,36 @@
+
+
+
+ |
+ A |
+ B |
+ C |
+
+
+ idx |
+ |
+ |
+ |
+
+
+
+
+ foo |
+ 1 |
+ 1.2 |
+ one |
+
+
+ bar |
+ 2 |
+ 3.4 |
+ two |
+
+
+ baz |
+ 3 |
+ 5.6 |
+ NaN |
+
+
+
diff --git a/pandas/tests/io/formats/data/index_4.html b/pandas/tests/io/formats/data/index_4.html
new file mode 100644
index 00000000000000..0d1bf9ffcd7173
--- /dev/null
+++ b/pandas/tests/io/formats/data/index_4.html
@@ -0,0 +1,33 @@
+
+
+
+ |
+ |
+ A |
+ B |
+ C |
+
+
+
+
+ foo |
+ car |
+ 1 |
+ 1.2 |
+ one |
+
+
+ bike |
+ 2 |
+ 3.4 |
+ two |
+
+
+ bar |
+ car |
+ 3 |
+ 5.6 |
+ NaN |
+
+
+
diff --git a/pandas/tests/io/formats/data/index_5.html b/pandas/tests/io/formats/data/index_5.html
new file mode 100644
index 00000000000000..c5ac12ecd630e1
--- /dev/null
+++ b/pandas/tests/io/formats/data/index_5.html
@@ -0,0 +1,40 @@
+
+
+
+ |
+ |
+ A |
+ B |
+ C |
+
+
+ idx1 |
+ idx2 |
+ |
+ |
+ |
+
+
+
+
+ foo |
+ car |
+ 1 |
+ 1.2 |
+ one |
+
+
+ bike |
+ 2 |
+ 3.4 |
+ two |
+
+
+ bar |
+ car |
+ 3 |
+ 5.6 |
+ NaN |
+
+
+
diff --git a/pandas/tests/io/formats/data/index_formatter.html b/pandas/tests/io/formats/data/index_formatter.html
new file mode 100644
index 00000000000000..7a2f8a9f52a040
--- /dev/null
+++ b/pandas/tests/io/formats/data/index_formatter.html
@@ -0,0 +1,31 @@
+
+
+
+ |
+ foo |
+ None |
+
+
+
+
+ a |
+ 0 |
+ 1 |
+
+
+ b |
+ 2 |
+ 3 |
+
+
+ c |
+ 4 |
+ 5 |
+
+
+ d |
+ 6 |
+ 7 |
+
+
+
diff --git a/pandas/tests/io/formats/data/justify.html b/pandas/tests/io/formats/data/justify.html
new file mode 100644
index 00000000000000..33e4b5715260e7
--- /dev/null
+++ b/pandas/tests/io/formats/data/justify.html
@@ -0,0 +1,30 @@
+
+
+
+ |
+ A |
+ B |
+ C |
+
+
+
+
+ 0 |
+ 6 |
+ 1 |
+ 223442 |
+
+
+ 1 |
+ 30000 |
+ 2 |
+ 0 |
+
+
+ 2 |
+ 2 |
+ 70000 |
+ 1 |
+
+
+
diff --git a/pandas/tests/io/formats/data/multiindex_1.html b/pandas/tests/io/formats/data/multiindex_1.html
new file mode 100644
index 00000000000000..88db1775459726
--- /dev/null
+++ b/pandas/tests/io/formats/data/multiindex_1.html
@@ -0,0 +1,32 @@
+
+
+
+ CL0 |
+ 0 |
+ 1 |
+
+
+ CL1 |
+ 0 |
+ 1 |
+ 0 |
+ 1 |
+
+
+
+
+ 0 |
+ a |
+ b |
+ c |
+ d |
+
+
+ 1 |
+ e |
+ f |
+ g |
+ h |
+
+
+
diff --git a/pandas/tests/io/formats/data/multiindex_2.html b/pandas/tests/io/formats/data/multiindex_2.html
new file mode 100644
index 00000000000000..289ea2202d6b93
--- /dev/null
+++ b/pandas/tests/io/formats/data/multiindex_2.html
@@ -0,0 +1,34 @@
+
+
+
+ |
+ 0 |
+ 1 |
+ 2 |
+ 3 |
+
+
+ |
+ 0 |
+ 1 |
+ 0 |
+ 1 |
+
+
+
+
+ 0 |
+ a |
+ b |
+ c |
+ d |
+
+
+ 1 |
+ e |
+ f |
+ g |
+ h |
+
+
+
diff --git a/pandas/tests/io/formats/data/multiindex_sparsify_1.html b/pandas/tests/io/formats/data/multiindex_sparsify_1.html
new file mode 100644
index 00000000000000..5b5bcf9ce0a96e
--- /dev/null
+++ b/pandas/tests/io/formats/data/multiindex_sparsify_1.html
@@ -0,0 +1,40 @@
+
+
+
+ |
+ |
+ 0 |
+ 1 |
+
+
+ foo |
+ |
+ |
+ |
+
+
+
+
+ 0 |
+ 0 |
+ 0 |
+ 1 |
+
+
+ 1 |
+ 2 |
+ 3 |
+
+
+ 1 |
+ 0 |
+ 4 |
+ 5 |
+
+
+ 1 |
+ 6 |
+ 7 |
+
+
+
diff --git a/pandas/tests/io/formats/data/multiindex_sparsify_2.html b/pandas/tests/io/formats/data/multiindex_sparsify_2.html
new file mode 100644
index 00000000000000..fd4c6bd23dae22
--- /dev/null
+++ b/pandas/tests/io/formats/data/multiindex_sparsify_2.html
@@ -0,0 +1,46 @@
+
+
+
+ |
+ foo |
+ 0 |
+ 1 |
+
+
+ |
+ |
+ 0 |
+ 0 |
+
+
+ foo |
+ |
+ |
+ |
+
+
+
+
+ 0 |
+ 0 |
+ 0 |
+ 1 |
+
+
+ 1 |
+ 2 |
+ 3 |
+
+
+ 1 |
+ 0 |
+ 4 |
+ 5 |
+
+
+ 1 |
+ 6 |
+ 7 |
+
+
+
diff --git a/pandas/tests/io/formats/data/multiindex_sparsify_false_multi_sparse_1.html b/pandas/tests/io/formats/data/multiindex_sparsify_false_multi_sparse_1.html
new file mode 100644
index 00000000000000..42a5ea5eb58994
--- /dev/null
+++ b/pandas/tests/io/formats/data/multiindex_sparsify_false_multi_sparse_1.html
@@ -0,0 +1,42 @@
+
+
+
+ |
+ |
+ 0 |
+ 1 |
+
+
+ foo |
+ |
+ |
+ |
+
+
+
+
+ 0 |
+ 0 |
+ 0 |
+ 1 |
+
+
+ 0 |
+ 1 |
+ 2 |
+ 3 |
+
+
+ 1 |
+ 0 |
+ 4 |
+ 5 |
+
+
+ 1 |
+ 1 |
+ 6 |
+ 7 |
+
+
+
diff --git a/pandas/tests/io/formats/data/multiindex_sparsify_false_multi_sparse_2.html b/pandas/tests/io/formats/data/multiindex_sparsify_false_multi_sparse_2.html
new file mode 100644
index 00000000000000..2be61392e85735
--- /dev/null
+++ b/pandas/tests/io/formats/data/multiindex_sparsify_false_multi_sparse_2.html
@@ -0,0 +1,48 @@
+
+
+
+ |
+ foo |
+ 0 |
+ 1 |
+
+
+ |
+ |
+ 0 |
+ 0 |
+
+
+ foo |
+ |
+ |
+ |
+
+
+
+
+ 0 |
+ 0 |
+ 0 |
+ 1 |
+
+
+ 0 |
+ 1 |
+ 2 |
+ 3 |
+
+
+ 1 |
+ 0 |
+ 4 |
+ 5 |
+
+
+ 1 |
+ 1 |
+ 6 |
+ 7 |
+
+
+
diff --git a/pandas/tests/io/formats/data/truncate.html b/pandas/tests/io/formats/data/truncate.html
new file mode 100644
index 00000000000000..a5eb8c5cdbb9b1
--- /dev/null
+++ b/pandas/tests/io/formats/data/truncate.html
@@ -0,0 +1,86 @@
+
+
+
+ |
+ 0 |
+ 1 |
+ ... |
+ 18 |
+ 19 |
+
+
+
+
+ 2001-01-01 |
+ NaN |
+ NaN |
+ ... |
+ NaN |
+ NaN |
+
+
+ 2001-01-02 |
+ NaN |
+ NaN |
+ ... |
+ NaN |
+ NaN |
+
+
+ 2001-01-03 |
+ NaN |
+ NaN |
+ ... |
+ NaN |
+ NaN |
+
+
+ 2001-01-04 |
+ NaN |
+ NaN |
+ ... |
+ NaN |
+ NaN |
+
+
+ ... |
+ ... |
+ ... |
+ ... |
+ ... |
+ ... |
+
+
+ 2001-01-17 |
+ NaN |
+ NaN |
+ ... |
+ NaN |
+ NaN |
+
+
+ 2001-01-18 |
+ NaN |
+ NaN |
+ ... |
+ NaN |
+ NaN |
+
+
+ 2001-01-19 |
+ NaN |
+ NaN |
+ ... |
+ NaN |
+ NaN |
+
+
+ 2001-01-20 |
+ NaN |
+ NaN |
+ ... |
+ NaN |
+ NaN |
+
+
+
diff --git a/pandas/tests/io/formats/data/truncate_multi_index.html b/pandas/tests/io/formats/data/truncate_multi_index.html
new file mode 100644
index 00000000000000..8a295d66db1307
--- /dev/null
+++ b/pandas/tests/io/formats/data/truncate_multi_index.html
@@ -0,0 +1,101 @@
+
+
+
+ |
+ |
+ bar |
+ baz |
+ ... |
+ foo |
+ qux |
+
+
+ |
+ |
+ one |
+ two |
+ one |
+ ... |
+ two |
+ one |
+ two |
+
+
+
+
+ bar |
+ one |
+ NaN |
+ NaN |
+ NaN |
+ ... |
+ NaN |
+ NaN |
+ NaN |
+
+
+ two |
+ NaN |
+ NaN |
+ NaN |
+ ... |
+ NaN |
+ NaN |
+ NaN |
+
+
+ baz |
+ one |
+ NaN |
+ NaN |
+ NaN |
+ ... |
+ NaN |
+ NaN |
+ NaN |
+
+
+ ... |
+ ... |
+ ... |
+ ... |
+ ... |
+ ... |
+ ... |
+ ... |
+ ... |
+
+
+ foo |
+ two |
+ NaN |
+ NaN |
+ NaN |
+ ... |
+ NaN |
+ NaN |
+ NaN |
+
+
+ qux |
+ one |
+ NaN |
+ NaN |
+ NaN |
+ ... |
+ NaN |
+ NaN |
+ NaN |
+
+
+ two |
+ NaN |
+ NaN |
+ NaN |
+ ... |
+ NaN |
+ NaN |
+ NaN |
+
+
+
diff --git a/pandas/tests/io/formats/data/truncate_multi_index_sparse_off.html b/pandas/tests/io/formats/data/truncate_multi_index_sparse_off.html
new file mode 100644
index 00000000000000..05c644dfbfe083
--- /dev/null
+++ b/pandas/tests/io/formats/data/truncate_multi_index_sparse_off.html
@@ -0,0 +1,94 @@
+
+
+
+ |
+ |
+ bar |
+ bar |
+ baz |
+ ... |
+ foo |
+ qux |
+ qux |
+
+
+ |
+ |
+ one |
+ two |
+ one |
+ ... |
+ two |
+ one |
+ two |
+
+
+
+
+ bar |
+ one |
+ NaN |
+ NaN |
+ NaN |
+ ... |
+ NaN |
+ NaN |
+ NaN |
+
+
+ bar |
+ two |
+ NaN |
+ NaN |
+ NaN |
+ ... |
+ NaN |
+ NaN |
+ NaN |
+
+
+ baz |
+ one |
+ NaN |
+ NaN |
+ NaN |
+ ... |
+ NaN |
+ NaN |
+ NaN |
+
+
+ foo |
+ two |
+ NaN |
+ NaN |
+ NaN |
+ ... |
+ NaN |
+ NaN |
+ NaN |
+
+
+ qux |
+ one |
+ NaN |
+ NaN |
+ NaN |
+ ... |
+ NaN |
+ NaN |
+ NaN |
+
+
+ qux |
+ two |
+ NaN |
+ NaN |
+ NaN |
+ ... |
+ NaN |
+ NaN |
+ NaN |
+
+
+
diff --git a/pandas/tests/io/formats/data/unicode_1.html b/pandas/tests/io/formats/data/unicode_1.html
new file mode 100644
index 00000000000000..72b810181badef
--- /dev/null
+++ b/pandas/tests/io/formats/data/unicode_1.html
@@ -0,0 +1,50 @@
+
+
+
+ |
+ σ |
+
+
+
+
+ 0 |
+ 0.0 |
+
+
+ 1 |
+ 1.0 |
+
+
+ 2 |
+ 2.0 |
+
+
+ 3 |
+ 3.0 |
+
+
+ 4 |
+ 4.0 |
+
+
+ 5 |
+ 5.0 |
+
+
+ 6 |
+ 6.0 |
+
+
+ 7 |
+ 7.0 |
+
+
+ 8 |
+ 8.0 |
+
+
+ 9 |
+ 9.0 |
+
+
+
diff --git a/pandas/tests/io/formats/data/unicode_2.html b/pandas/tests/io/formats/data/unicode_2.html
new file mode 100644
index 00000000000000..79c088093e539b
--- /dev/null
+++ b/pandas/tests/io/formats/data/unicode_2.html
@@ -0,0 +1,14 @@
+
+
+
+ |
+ A |
+
+
+
+
+ 0 |
+ σ |
+
+
+
diff --git a/pandas/tests/io/formats/data/with_classes.html b/pandas/tests/io/formats/data/with_classes.html
new file mode 100644
index 00000000000000..8cee3f0c7052bb
--- /dev/null
+++ b/pandas/tests/io/formats/data/with_classes.html
@@ -0,0 +1,9 @@
+
diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py
index 32cf21ddf5f38c..0da48f60f1b516 100644
--- a/pandas/tests/io/formats/test_to_html.py
+++ b/pandas/tests/io/formats/test_to_html.py
@@ -1,9 +1,8 @@
# -*- coding: utf-8 -*-
import re
-from textwrap import dedent
from datetime import datetime
-from distutils.version import LooseVersion
+from io import open
import pytest
import numpy as np
@@ -13,14 +12,6 @@
from pandas.util import testing as tm
import pandas.io.formats.format as fmt
-div_style = ''
-try:
- import IPython
- if LooseVersion(IPython.__version__) < LooseVersion('3.0.0'):
- div_style = ' style="max-width:1500px;overflow:auto;"'
-except (ImportError, AttributeError):
- pass
-
def expected_html(datapath, name):
"""
@@ -39,7 +30,7 @@ def expected_html(datapath, name):
"""
filename = '.'.join([name, 'html'])
filepath = datapath('io', 'formats', 'data', filename)
- with open(filepath) as f:
+ with open(filepath, encoding='utf-8') as f:
html = f.read()
return html.rstrip()
@@ -63,49 +54,28 @@ def check_with_width(df, col_space):
check_with_width(df, 50)
def test_to_html_with_empty_string_label(self):
- # GH3547, to_html regards empty string labels as repeated labels
+ # GH 3547, to_html regards empty string labels as repeated labels
data = {'c1': ['a', 'b'], 'c2': ['a', ''], 'data': [1, 2]}
df = DataFrame(data).set_index(['c1', 'c2'])
- res = df.to_html()
- assert "rowspan" not in res
+ result = df.to_html()
+ assert "rowspan" not in result
- def test_to_html_unicode(self):
+ def test_to_html_unicode(self, datapath):
df = DataFrame({u('\u03c3'): np.arange(10.)})
- expected = u'\n \n \n | \n \u03c3 | \n
\n \n \n \n 0 | \n 0.0 | \n
\n \n 1 | \n 1.0 | \n
\n \n 2 | \n 2.0 | \n
\n \n 3 | \n 3.0 | \n
\n \n 4 | \n 4.0 | \n
\n \n 5 | \n 5.0 | \n
\n \n 6 | \n 6.0 | \n
\n \n 7 | \n 7.0 | \n
\n \n 8 | \n 8.0 | \n
\n \n 9 | \n 9.0 | \n
\n \n
' # noqa
+ expected = expected_html(datapath, 'unicode_1')
assert df.to_html() == expected
df = DataFrame({'A': [u('\u03c3')]})
- expected = u'\n \n \n | \n A | \n
\n \n \n \n 0 | \n \u03c3 | \n
\n \n
' # noqa
+ expected = expected_html(datapath, 'unicode_2')
assert df.to_html() == expected
- def test_to_html_decimal(self):
+ def test_to_html_decimal(self, datapath):
# GH 12031
df = DataFrame({'A': [6.0, 3.1, 2.2]})
result = df.to_html(decimal=',')
- expected = ('\n'
- ' \n'
- ' \n'
- ' | \n'
- ' A | \n'
- '
\n'
- ' \n'
- ' \n'
- ' \n'
- ' 0 | \n'
- ' 6,0 | \n'
- '
\n'
- ' \n'
- ' 1 | \n'
- ' 3,1 | \n'
- '
\n'
- ' \n'
- ' 2 | \n'
- ' 2,2 | \n'
- '
\n'
- ' \n'
- '
')
+ expected = expected_html(datapath, 'gh12031_expected_output')
assert result == expected
- def test_to_html_escaped(self):
+ def test_to_html_escaped(self, datapath):
a = 'str"},
'co>l2': {a: "",
b: ""}}
- rs = DataFrame(test_dict).to_html()
- xp = """
-
-
- |
- co<l1 |
- co>l2 |
-
-
-
-
- str<ing1 & |
- <type 'str'> |
- <type 'str'> |
-
-
- stri>ng2 & |
- <type 'str'> |
- <type 'str'> |
-
-
-
"""
-
- assert xp == rs
-
- def test_to_html_escape_disabled(self):
+ result = DataFrame(test_dict).to_html()
+ expected = expected_html(datapath, 'escaped')
+ assert result == expected
+
+ def test_to_html_escape_disabled(self, datapath):
a = 'strbold"},
'co>l2': {a: "bold",
b: "bold"}}
- rs = DataFrame(test_dict).to_html(escape=False)
- xp = """
-
-
- |
- co
- co>l2 |
- |
-
-
-
- str
- bold |
- bold |
- |
-
- stri>ng2 & |
- bold |
- bold |
-
-
-
"""
-
- assert xp == rs
-
- def test_to_html_multiindex_index_false(self):
- # issue 8452
+ result = DataFrame(test_dict).to_html(escape=False)
+ expected = expected_html(datapath, 'escape_disabled')
+ assert result == expected
+
+ def test_to_html_multiindex_index_false(self, datapath):
+ # GH 8452
df = DataFrame({
'a': range(2),
'b': range(3, 5),
@@ -181,257 +109,47 @@ def test_to_html_multiindex_index_false(self):
})
df.columns = MultiIndex.from_product([['a', 'b'], ['c', 'd']])
result = df.to_html(index=False)
- expected = """\
-
-
-
- a |
- b |
-
-
- c |
- d |
- c |
- d |
-
-
-
-
- 0 |
- 3 |
- 5 |
- 3 |
-
-
- 1 |
- 4 |
- 6 |
- 4 |
-
-
-
"""
-
+ expected = expected_html(datapath, 'gh8452_expected_output')
assert result == expected
df.index = Index(df.index.values, name='idx')
result = df.to_html(index=False)
assert result == expected
- def test_to_html_multiindex_sparsify_false_multi_sparse(self):
+ def test_to_html_multiindex_sparsify_false_multi_sparse(self, datapath):
with option_context('display.multi_sparse', False):
index = MultiIndex.from_arrays([[0, 0, 1, 1], [0, 1, 0, 1]],
names=['foo', None])
df = DataFrame([[0, 1], [2, 3], [4, 5], [6, 7]], index=index)
-
result = df.to_html()
- expected = """\
-
-
-
- |
- |
- 0 |
- 1 |
-
-
- foo |
- |
- |
- |
-
-
-
-
- 0 |
- 0 |
- 0 |
- 1 |
-
-
- 0 |
- 1 |
- 2 |
- 3 |
-
-
- 1 |
- 0 |
- 4 |
- 5 |
-
-
- 1 |
- 1 |
- 6 |
- 7 |
-
-
-
"""
-
+ expected = expected_html(
+ datapath, 'multiindex_sparsify_false_multi_sparse_1')
assert result == expected
df = DataFrame([[0, 1], [2, 3], [4, 5], [6, 7]],
columns=index[::2], index=index)
-
result = df.to_html()
- expected = """\
-
-
-
- |
- foo |
- 0 |
- 1 |
-
-
- |
- |
- 0 |
- 0 |
-
-
- foo |
- |
- |
- |
-
-
-
-
- 0 |
- 0 |
- 0 |
- 1 |
-
-
- 0 |
- 1 |
- 2 |
- 3 |
-
-
- 1 |
- 0 |
- 4 |
- 5 |
-
-
- 1 |
- 1 |
- 6 |
- 7 |
-
-
-
"""
-
+ expected = expected_html(
+ datapath, 'multiindex_sparsify_false_multi_sparse_2')
assert result == expected
- def test_to_html_multiindex_sparsify(self):
+ def test_to_html_multiindex_sparsify(self, datapath):
index = MultiIndex.from_arrays([[0, 0, 1, 1], [0, 1, 0, 1]],
names=['foo', None])
df = DataFrame([[0, 1], [2, 3], [4, 5], [6, 7]], index=index)
-
result = df.to_html()
- expected = """
-
-
- |
- |
- 0 |
- 1 |
-
-
- foo |
- |
- |
- |
-
-
-
-
- 0 |
- 0 |
- 0 |
- 1 |
-
-
- 1 |
- 2 |
- 3 |
-
-
- 1 |
- 0 |
- 4 |
- 5 |
-
-
- 1 |
- 6 |
- 7 |
-
-
-
"""
-
+ expected = expected_html(datapath, 'multiindex_sparsify_1')
assert result == expected
df = DataFrame([[0, 1], [2, 3], [4, 5], [6, 7]], columns=index[::2],
index=index)
-
result = df.to_html()
- expected = """\
-
-
-
- |
- foo |
- 0 |
- 1 |
-
-
- |
- |
- 0 |
- 0 |
-
-
- foo |
- |
- |
- |
-
-
-
-
- 0 |
- 0 |
- 0 |
- 1 |
-
-
- 1 |
- 2 |
- 3 |
-
-
- 1 |
- 0 |
- 4 |
- 5 |
-
-
- 1 |
- 6 |
- 7 |
-
-
-
"""
-
+ expected = expected_html(datapath, 'multiindex_sparsify_2')
assert result == expected
- def test_to_html_multiindex_odd_even_truncate(self):
+ def test_to_html_multiindex_odd_even_truncate(self, datapath):
# GH 14882 - Issue on truncation with odd length DataFrame
mi = MultiIndex.from_product([[100, 200, 300],
[10, 20, 30],
@@ -439,616 +157,34 @@ def test_to_html_multiindex_odd_even_truncate(self):
names=['a', 'b', 'c'])
df = DataFrame({'n': range(len(mi))}, index=mi)
result = df.to_html(max_rows=60)
- expected = """\
-
-
-
- |
- |
- |
- n |
-
-
- a |
- b |
- c |
- |
-
-
-
-
- 100 |
- 10 |
- 1 |
- 0 |
-
-
- 2 |
- 1 |
-
-
- 3 |
- 2 |
-
-
- 4 |
- 3 |
-
-
- 5 |
- 4 |
-
-
- 6 |
- 5 |
-
-
- 7 |
- 6 |
-
-
- 20 |
- 1 |
- 7 |
-
-
- 2 |
- 8 |
-
-
- 3 |
- 9 |
-
-
- 4 |
- 10 |
-
-
- 5 |
- 11 |
-
-
- 6 |
- 12 |
-
-
- 7 |
- 13 |
-
-
- 30 |
- 1 |
- 14 |
-
-
- 2 |
- 15 |
-
-
- 3 |
- 16 |
-
-
- 4 |
- 17 |
-
-
- 5 |
- 18 |
-
-
- 6 |
- 19 |
-
-
- 7 |
- 20 |
-
-
- 200 |
- 10 |
- 1 |
- 21 |
-
-
- 2 |
- 22 |
-
-
- 3 |
- 23 |
-
-
- 4 |
- 24 |
-
-
- 5 |
- 25 |
-
-
- 6 |
- 26 |
-
-
- 7 |
- 27 |
-
-
- 20 |
- 1 |
- 28 |
-
-
- 2 |
- 29 |
-
-
- ... |
- ... |
-
-
- 6 |
- 33 |
-
-
- 7 |
- 34 |
-
-
- 30 |
- 1 |
- 35 |
-
-
- 2 |
- 36 |
-
-
- 3 |
- 37 |
-
-
- 4 |
- 38 |
-
-
- 5 |
- 39 |
-
-
- 6 |
- 40 |
-
-
- 7 |
- 41 |
-
-
- 300 |
- 10 |
- 1 |
- 42 |
-
-
- 2 |
- 43 |
-
-
- 3 |
- 44 |
-
-
- 4 |
- 45 |
-
-
- 5 |
- 46 |
-
-
- 6 |
- 47 |
-
-
- 7 |
- 48 |
-
-
- 20 |
- 1 |
- 49 |
-
-
- 2 |
- 50 |
-
-
- 3 |
- 51 |
-
-
- 4 |
- 52 |
-
-
- 5 |
- 53 |
-
-
- 6 |
- 54 |
-
-
- 7 |
- 55 |
-
-
- 30 |
- 1 |
- 56 |
-
-
- 2 |
- 57 |
-
-
- 3 |
- 58 |
-
-
- 4 |
- 59 |
-
-
- 5 |
- 60 |
-
-
- 6 |
- 61 |
-
-
- 7 |
- 62 |
-
-
-
"""
+ expected = expected_html(datapath, 'gh14882_expected_output_1')
assert result == expected
# Test that ... appears in a middle level
result = df.to_html(max_rows=56)
- expected = """\
-
-
-
- |
- |
- |
- n |
-
-
- a |
- b |
- c |
- |
-
-
-
-
- 100 |
- 10 |
- 1 |
- 0 |
-
-
- 2 |
- 1 |
-
-
- 3 |
- 2 |
-
-
- 4 |
- 3 |
-
-
- 5 |
- 4 |
-
-
- 6 |
- 5 |
-
-
- 7 |
- 6 |
-
-
- 20 |
- 1 |
- 7 |
-
-
- 2 |
- 8 |
-
-
- 3 |
- 9 |
-
-
- 4 |
- 10 |
-
-
- 5 |
- 11 |
-
-
- 6 |
- 12 |
-
-
- 7 |
- 13 |
-
-
- 30 |
- 1 |
- 14 |
-
-
- 2 |
- 15 |
-
-
- 3 |
- 16 |
-
-
- 4 |
- 17 |
-
-
- 5 |
- 18 |
-
-
- 6 |
- 19 |
-
-
- 7 |
- 20 |
-
-
- 200 |
- 10 |
- 1 |
- 21 |
-
-
- 2 |
- 22 |
-
-
- 3 |
- 23 |
-
-
- 4 |
- 24 |
-
-
- 5 |
- 25 |
-
-
- 6 |
- 26 |
-
-
- 7 |
- 27 |
-
-
- ... |
- ... |
- ... |
-
-
- 30 |
- 1 |
- 35 |
-
-
- 2 |
- 36 |
-
-
- 3 |
- 37 |
-
-
- 4 |
- 38 |
-
-
- 5 |
- 39 |
-
-
- 6 |
- 40 |
-
-
- 7 |
- 41 |
-
-
- 300 |
- 10 |
- 1 |
- 42 |
-
-
- 2 |
- 43 |
-
-
- 3 |
- 44 |
-
-
- 4 |
- 45 |
-
-
- 5 |
- 46 |
-
-
- 6 |
- 47 |
-
-
- 7 |
- 48 |
-
-
- 20 |
- 1 |
- 49 |
-
-
- 2 |
- 50 |
-
-
- 3 |
- 51 |
-
-
- 4 |
- 52 |
-
-
- 5 |
- 53 |
-
-
- 6 |
- 54 |
-
-
- 7 |
- 55 |
-
-
- 30 |
- 1 |
- 56 |
-
-
- 2 |
- 57 |
-
-
- 3 |
- 58 |
-
-
- 4 |
- 59 |
-
-
- 5 |
- 60 |
-
-
- 6 |
- 61 |
-
-
- 7 |
- 62 |
-
-
-
"""
+ expected = expected_html(datapath, 'gh14882_expected_output_2')
assert result == expected
- def test_to_html_index_formatter(self):
+ def test_to_html_index_formatter(self, datapath):
df = DataFrame([[0, 1], [2, 3], [4, 5], [6, 7]], columns=['foo', None],
index=lrange(4))
f = lambda x: 'abcd' [x]
result = df.to_html(formatters={'__index__': f})
- expected = """\
-
-
-
- |
- foo |
- None |
-
-
-
-
- a |
- 0 |
- 1 |
-
-
- b |
- 2 |
- 3 |
-
-
- c |
- 4 |
- 5 |
-
-
- d |
- 6 |
- 7 |
-
-
-
"""
-
+ expected = expected_html(datapath, 'index_formatter')
assert result == expected
- def test_to_html_datetime64_monthformatter(self):
+ def test_to_html_datetime64_monthformatter(self, datapath):
months = [datetime(2016, 1, 1), datetime(2016, 2, 2)]
x = DataFrame({'months': months})
def format_func(x):
return x.strftime('%Y-%m')
result = x.to_html(formatters={'months': format_func})
- expected = """\
-
-
-
- |
- months |
-
-
-
-
- 0 |
- 2016-01 |
-
-
- 1 |
- 2016-02 |
-
-
-
"""
+ expected = expected_html(datapath, 'datetime64_monthformatter')
assert result == expected
- def test_to_html_datetime64_hourformatter(self):
+ def test_to_html_datetime64_hourformatter(self, datapath):
x = DataFrame({'hod': pd.to_datetime(['10:10:10.100', '12:12:12.120'],
format='%H:%M:%S.%f')})
@@ -1056,25 +192,7 @@ def test_to_html_datetime64_hourformatter(self):
def format_func(x):
return x.strftime('%H:%M')
result = x.to_html(formatters={'hod': format_func})
- expected = """\
-
-
-
- |
- hod |
-
-
-
-
- 0 |
- 10:10 |
-
-
- 1 |
- 12:12 |
-
-
-
"""
+ expected = expected_html(datapath, 'datetime64_hourformatter')
assert result == expected
def test_to_html_regression_GH6098(self):
@@ -1087,309 +205,28 @@ def test_to_html_regression_GH6098(self):
# it works
df.pivot_table(index=[u('clé1')], columns=[u('clé2')])._repr_html_()
- def test_to_html_truncate(self):
+ def test_to_html_truncate(self, datapath):
index = pd.DatetimeIndex(start='20010101', freq='D', periods=20)
df = DataFrame(index=index, columns=range(20))
result = df.to_html(max_rows=8, max_cols=4)
- expected = '''\
-
-
-
- |
- 0 |
- 1 |
- ... |
- 18 |
- 19 |
-
-
-
-
- 2001-01-01 |
- NaN |
- NaN |
- ... |
- NaN |
- NaN |
-
-
- 2001-01-02 |
- NaN |
- NaN |
- ... |
- NaN |
- NaN |
-
-
- 2001-01-03 |
- NaN |
- NaN |
- ... |
- NaN |
- NaN |
-
-
- 2001-01-04 |
- NaN |
- NaN |
- ... |
- NaN |
- NaN |
-
-
- ... |
- ... |
- ... |
- ... |
- ... |
- ... |
-
-
- 2001-01-17 |
- NaN |
- NaN |
- ... |
- NaN |
- NaN |
-
-
- 2001-01-18 |
- NaN |
- NaN |
- ... |
- NaN |
- NaN |
-
-
- 2001-01-19 |
- NaN |
- NaN |
- ... |
- NaN |
- NaN |
-
-
- 2001-01-20 |
- NaN |
- NaN |
- ... |
- NaN |
- NaN |
-
-
-
'''
+ expected = expected_html(datapath, 'truncate')
assert result == expected
- def test_to_html_truncate_multi_index(self):
+ def test_to_html_truncate_multi_index(self, datapath):
arrays = [['bar', 'bar', 'baz', 'baz', 'foo', 'foo', 'qux', 'qux'],
['one', 'two', 'one', 'two', 'one', 'two', 'one', 'two']]
df = DataFrame(index=arrays, columns=arrays)
result = df.to_html(max_rows=7, max_cols=7)
- expected = '''\
-
-
-
- |
- |
- bar |
- baz |
- ... |
- foo |
- qux |
-
-
- |
- |
- one |
- two |
- one |
- ... |
- two |
- one |
- two |
-
-
-
-
- bar |
- one |
- NaN |
- NaN |
- NaN |
- ... |
- NaN |
- NaN |
- NaN |
-
-
- two |
- NaN |
- NaN |
- NaN |
- ... |
- NaN |
- NaN |
- NaN |
-
-
- baz |
- one |
- NaN |
- NaN |
- NaN |
- ... |
- NaN |
- NaN |
- NaN |
-
-
- ... |
- ... |
- ... |
- ... |
- ... |
- ... |
- ... |
- ... |
- ... |
-
-
- foo |
- two |
- NaN |
- NaN |
- NaN |
- ... |
- NaN |
- NaN |
- NaN |
-
-
- qux |
- one |
- NaN |
- NaN |
- NaN |
- ... |
- NaN |
- NaN |
- NaN |
-
-
- two |
- NaN |
- NaN |
- NaN |
- ... |
- NaN |
- NaN |
- NaN |
-
-
-
'''
+ expected = expected_html(datapath, 'truncate_multi_index')
assert result == expected
@pytest.mark.xfail(reason='GH22887 TypeError', strict=True)
- def test_to_html_truncate_multi_index_sparse_off(self):
+ def test_to_html_truncate_multi_index_sparse_off(self, datapath):
arrays = [['bar', 'bar', 'baz', 'baz', 'foo', 'foo', 'qux', 'qux'],
['one', 'two', 'one', 'two', 'one', 'two', 'one', 'two']]
df = DataFrame(index=arrays, columns=arrays)
result = df.to_html(max_rows=7, max_cols=7, sparsify=False)
- expected = '''\
-
-
-
- |
- |
- bar |
- bar |
- baz |
- ... |
- foo |
- qux |
- qux |
-
-
- |
- |
- one |
- two |
- one |
- ... |
- two |
- one |
- two |
-
-
-
-
- bar |
- one |
- NaN |
- NaN |
- NaN |
- ... |
- NaN |
- NaN |
- NaN |
-
-
- bar |
- two |
- NaN |
- NaN |
- NaN |
- ... |
- NaN |
- NaN |
- NaN |
-
-
- baz |
- one |
- NaN |
- NaN |
- NaN |
- ... |
- NaN |
- NaN |
- NaN |
-
-
- foo |
- two |
- NaN |
- NaN |
- NaN |
- ... |
- NaN |
- NaN |
- NaN |
-
-
- qux |
- one |
- NaN |
- NaN |
- NaN |
- ... |
- NaN |
- NaN |
- NaN |
-
-
- qux |
- two |
- NaN |
- NaN |
- NaN |
- ... |
- NaN |
- NaN |
- NaN |
-
-
-
'''
+ expected = expected_html(datapath, 'truncate_multi_index_sparse_off')
assert result == expected
def test_to_html_border(self):
@@ -1399,7 +236,7 @@ def test_to_html_border(self):
def test_to_html_border_option(self):
df = DataFrame({'A': [1, 2]})
- with pd.option_context('display.html.border', 0):
+ with option_context('display.html.border', 0):
result = df.to_html()
assert 'border="0"' in result
assert 'border="0"' in df._repr_html_()
@@ -1472,45 +309,13 @@ def test_to_html_columns_arg(self):
result = frame.to_html(columns=['A'])
assert 'B | ' not in result
- def test_to_html_multiindex(self):
+ def test_to_html_multiindex(self, datapath):
columns = MultiIndex.from_tuples(list(zip(np.arange(2).repeat(2),
np.mod(lrange(4), 2))),
names=['CL0', 'CL1'])
df = DataFrame([list('abcd'), list('efgh')], columns=columns)
result = df.to_html(justify='left')
- expected = ('\n'
- ' \n'
- ' \n'
- ' CL0 | \n'
- ' 0 | \n'
- ' 1 | \n'
- '
\n'
- ' \n'
- ' CL1 | \n'
- ' 0 | \n'
- ' 1 | \n'
- ' 0 | \n'
- ' 1 | \n'
- '
\n'
- ' \n'
- ' \n'
- ' \n'
- ' 0 | \n'
- ' a | \n'
- ' b | \n'
- ' c | \n'
- ' d | \n'
- '
\n'
- ' \n'
- ' 1 | \n'
- ' e | \n'
- ' f | \n'
- ' g | \n'
- ' h | \n'
- '
\n'
- ' \n'
- '
')
-
+ expected = expected_html(datapath, 'multiindex_1')
assert result == expected
columns = MultiIndex.from_tuples(list(zip(
@@ -1519,237 +324,53 @@ def test_to_html_multiindex(self):
df = DataFrame([list('abcd'), list('efgh')], columns=columns)
result = df.to_html(justify='right')
- expected = ('\n'
- ' \n'
- ' \n'
- ' | \n'
- ' 0 | \n'
- ' 1 | \n'
- ' 2 | \n'
- ' 3 | \n'
- '
\n'
- ' \n'
- ' | \n'
- ' 0 | \n'
- ' 1 | \n'
- ' 0 | \n'
- ' 1 | \n'
- '
\n'
- ' \n'
- ' \n'
- ' \n'
- ' 0 | \n'
- ' a | \n'
- ' b | \n'
- ' c | \n'
- ' d | \n'
- '
\n'
- ' \n'
- ' 1 | \n'
- ' e | \n'
- ' f | \n'
- ' g | \n'
- ' h | \n'
- '
\n'
- ' \n'
- '
')
-
+ expected = expected_html(datapath, 'multiindex_2')
assert result == expected
@pytest.mark.parametrize("justify", fmt._VALID_JUSTIFY_PARAMETERS)
- def test_to_html_justify(self, justify):
+ def test_to_html_justify(self, justify, datapath):
df = DataFrame({'A': [6, 30000, 2],
'B': [1, 2, 70000],
'C': [223442, 0, 1]},
columns=['A', 'B', 'C'])
result = df.to_html(justify=justify)
- expected = ('\n'
- ' \n'
- ' \n'
- ' | \n'
- ' A | \n'
- ' B | \n'
- ' C | \n'
- '
\n'
- ' \n'
- ' \n'
- ' \n'
- ' 0 | \n'
- ' 6 | \n'
- ' 1 | \n'
- ' 223442 | \n'
- '
\n'
- ' \n'
- ' 1 | \n'
- ' 30000 | \n'
- ' 2 | \n'
- ' 0 | \n'
- '
\n'
- ' \n'
- ' 2 | \n'
- ' 2 | \n'
- ' 70000 | \n'
- ' 1 | \n'
- '
\n'
- ' \n'
- '
'.format(justify=justify))
+ expected = expected_html(datapath, 'justify').format(justify=justify)
assert result == expected
@pytest.mark.parametrize("justify", ["super-right", "small-left",
"noinherit", "tiny", "pandas"])
def test_to_html_invalid_justify(self, justify):
- # see gh-17527
+ # GH 17527
df = DataFrame()
msg = "Invalid value for justify parameter"
with pytest.raises(ValueError, match=msg):
df.to_html(justify=justify)
- def test_to_html_index(self):
+ def test_to_html_index(self, datapath):
index = ['foo', 'bar', 'baz']
df = DataFrame({'A': [1, 2, 3],
'B': [1.2, 3.4, 5.6],
'C': ['one', 'two', np.nan]},
columns=['A', 'B', 'C'],
index=index)
- expected_with_index = ('\n'
- ' \n'
- ' \n'
- ' | \n'
- ' A | \n'
- ' B | \n'
- ' C | \n'
- '
\n'
- ' \n'
- ' \n'
- ' \n'
- ' foo | \n'
- ' 1 | \n'
- ' 1.2 | \n'
- ' one | \n'
- '
\n'
- ' \n'
- ' bar | \n'
- ' 2 | \n'
- ' 3.4 | \n'
- ' two | \n'
- '
\n'
- ' \n'
- ' baz | \n'
- ' 3 | \n'
- ' 5.6 | \n'
- ' NaN | \n'
- '
\n'
- ' \n'
- '
')
+ expected_with_index = expected_html(datapath, 'index_1')
assert df.to_html() == expected_with_index
- expected_without_index = ('\n'
- ' \n'
- ' \n'
- ' A | \n'
- ' B | \n'
- ' C | \n'
- '
\n'
- ' \n'
- ' \n'
- ' \n'
- ' 1 | \n'
- ' 1.2 | \n'
- ' one | \n'
- '
\n'
- ' \n'
- ' 2 | \n'
- ' 3.4 | \n'
- ' two | \n'
- '
\n'
- ' \n'
- ' 3 | \n'
- ' 5.6 | \n'
- ' NaN | \n'
- '
\n'
- ' \n'
- '
')
+ expected_without_index = expected_html(datapath, 'index_2')
result = df.to_html(index=False)
for i in index:
assert i not in result
assert result == expected_without_index
df.index = Index(['foo', 'bar', 'baz'], name='idx')
- expected_with_index = ('\n'
- ' \n'
- ' \n'
- ' | \n'
- ' A | \n'
- ' B | \n'
- ' C | \n'
- '
\n'
- ' \n'
- ' idx | \n'
- ' | \n'
- ' | \n'
- ' | \n'
- '
\n'
- ' \n'
- ' \n'
- ' \n'
- ' foo | \n'
- ' 1 | \n'
- ' 1.2 | \n'
- ' one | \n'
- '
\n'
- ' \n'
- ' bar | \n'
- ' 2 | \n'
- ' 3.4 | \n'
- ' two | \n'
- '
\n'
- ' \n'
- ' baz | \n'
- ' 3 | \n'
- ' 5.6 | \n'
- ' NaN | \n'
- '
\n'
- ' \n'
- '
')
+ expected_with_index = expected_html(datapath, 'index_3')
assert df.to_html() == expected_with_index
assert df.to_html(index=False) == expected_without_index
tuples = [('foo', 'car'), ('foo', 'bike'), ('bar', 'car')]
df.index = MultiIndex.from_tuples(tuples)
- expected_with_index = ('\n'
- ' \n'
- ' \n'
- ' | \n'
- ' | \n'
- ' A | \n'
- ' B | \n'
- ' C | \n'
- '
\n'
- ' \n'
- ' \n'
- ' \n'
- ' foo | \n'
- ' car | \n'
- ' 1 | \n'
- ' 1.2 | \n'
- ' one | \n'
- '
\n'
- ' \n'
- ' bike | \n'
- ' 2 | \n'
- ' 3.4 | \n'
- ' two | \n'
- '
\n'
- ' \n'
- ' bar | \n'
- ' car | \n'
- ' 3 | \n'
- ' 5.6 | \n'
- ' NaN | \n'
- '
\n'
- ' \n'
- '
')
+ expected_with_index = expected_html(datapath, 'index_4')
assert df.to_html() == expected_with_index
result = df.to_html(index=False)
@@ -1759,90 +380,27 @@ def test_to_html_index(self):
assert result == expected_without_index
df.index = MultiIndex.from_tuples(tuples, names=['idx1', 'idx2'])
- expected_with_index = ('\n'
- ' \n'
- ' \n'
- ' | \n'
- ' | \n'
- ' A | \n'
- ' B | \n'
- ' C | \n'
- '
\n'
- ' \n'
- ' idx1 | \n'
- ' idx2 | \n'
- ' | \n'
- ' | \n'
- ' | \n'
- '
\n'
- ' \n'
- ' \n'
- ' \n'
- ' foo | \n'
- ' car | \n'
- ' 1 | \n'
- ' 1.2 | \n'
- ' one | \n'
- '
\n'
- ' \n'
- ' bike | \n'
- ' 2 | \n'
- ' 3.4 | \n'
- ' two | \n'
- '
\n'
- ' \n'
- ' bar | \n'
- ' car | \n'
- ' 3 | \n'
- ' 5.6 | \n'
- ' NaN | \n'
- '
\n'
- ' \n'
- '
')
+ expected_with_index = expected_html(datapath, 'index_5')
assert df.to_html() == expected_with_index
assert df.to_html(index=False) == expected_without_index
- def test_to_html_with_classes(self):
+ def test_to_html_with_classes(self, datapath):
df = DataFrame()
result = df.to_html(classes="sortable draggable")
- expected = dedent("""
-
-
-
- """).strip()
+ expected = expected_html(datapath, 'with_classes')
assert result == expected
result = df.to_html(classes=["sortable", "draggable"])
assert result == expected
- def test_to_html_no_index_max_rows(self):
- # GH https://github.com/pandas-dev/pandas/issues/14998
+ def test_to_html_no_index_max_rows(self, datapath):
+ # GH 14998
df = DataFrame({"A": [1, 2, 3, 4]})
result = df.to_html(index=False, max_rows=1)
- expected = dedent("""\
-
-
-
- A |
-
-
-
-
- 1 |
-
-
-
""")
+ expected = expected_html(datapath, 'gh14998_expected_output')
assert result == expected
- def test_to_html_multiindex_max_cols(self):
+ def test_to_html_multiindex_max_cols(self, datapath):
# GH 6131
index = MultiIndex(levels=[['ba', 'bb', 'bc'], ['ca', 'cb', 'cc']],
labels=[[0, 1, 2], [0, 1, 2]],
@@ -1854,53 +412,7 @@ def test_to_html_multiindex_max_cols(self):
[[1., np.nan, np.nan], [np.nan, 2., np.nan], [np.nan, np.nan, 3.]])
df = DataFrame(data, index, columns)
result = df.to_html(max_cols=2)
- expected = dedent("""\
-
-
-
- |
- |
- d |
-
-
- |
- a |
- aa |
- ... |
- ac |
-
-
- b |
- c |
- |
- |
- |
-
-
-
-
- ba |
- ca |
- 1.0 |
- ... |
- NaN |
-
-
- bb |
- cb |
- NaN |
- ... |
- NaN |
-
-
- bc |
- cc |
- NaN |
- ... |
- 3.0 |
-
-
-
""")
+ expected = expected_html(datapath, 'gh6131_expected_output')
assert result == expected
@pytest.mark.parametrize('index', [False, 0])
@@ -1911,7 +423,7 @@ def test_to_html_truncation_index_false_max_rows(self, datapath, index):
[1.867558, -0.977278],
[0.950088, -0.151357],
[-0.103219, 0.410599]]
- df = pd.DataFrame(data)
+ df = DataFrame(data)
result = df.to_html(max_rows=4, index=index)
expected = expected_html(datapath, 'gh15019_expected_output')
assert result == expected
@@ -1921,35 +433,35 @@ def test_to_html_truncation_index_false_max_cols(self, datapath, index):
# GH 22783
data = [[1.764052, 0.400157, 0.978738, 2.240893, 1.867558],
[-0.977278, 0.950088, -0.151357, -0.103219, 0.410599]]
- df = pd.DataFrame(data)
+ df = DataFrame(data)
result = df.to_html(max_cols=4, index=index)
expected = expected_html(datapath, 'gh22783_expected_output')
assert result == expected
def test_to_html_notebook_has_style(self):
- df = pd.DataFrame({"A": [1, 2, 3]})
+ df = DataFrame({"A": [1, 2, 3]})
result = df.to_html(notebook=True)
assert "tbody tr th:only-of-type" in result
assert "vertical-align: middle;" in result
assert "thead th" in result
def test_to_html_notebook_has_no_style(self):
- df = pd.DataFrame({"A": [1, 2, 3]})
+ df = DataFrame({"A": [1, 2, 3]})
result = df.to_html()
assert "tbody tr th:only-of-type" not in result
assert "vertical-align: middle;" not in result
assert "thead th" not in result
def test_to_html_with_index_names_false(self):
- # gh-16493
- df = pd.DataFrame({"A": [1, 2]}, index=pd.Index(['a', 'b'],
- name='myindexname'))
+ # GH 16493
+ df = DataFrame({"A": [1, 2]}, index=Index(['a', 'b'],
+ name='myindexname'))
result = df.to_html(index_names=False)
assert 'myindexname' not in result
def test_to_html_with_id(self):
- # gh-8496
- df = pd.DataFrame({"A": [1, 2]}, index=pd.Index(['a', 'b'],
- name='myindexname'))
+ # GH 8496
+ df = DataFrame({"A": [1, 2]}, index=Index(['a', 'b'],
+ name='myindexname'))
result = df.to_html(index_names=False, table_id="TEST_ID")
assert ' id="TEST_ID"' in result