Skip to content

Commit 301135c

Browse files
committed
Fix DataFrame._repr_html_().
1 parent c8c2214 commit 301135c

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

databricks/koalas/frame.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8310,7 +8310,7 @@ def _repr_html_(self):
83108310

83118311
pdf = self.head(max_display_count + 1)._to_internal_pandas()
83128312
pdf_length = len(pdf)
8313-
pdf = pdf[:max_display_count]
8313+
pdf = pdf.iloc[:max_display_count]
83148314
if pdf_length > max_display_count:
83158315
repr_html = pdf.to_html(show_dimensions=True, notebook=True, bold_rows=bold_rows)
83168316
match = REPR_HTML_PATTERN.search(repr_html)

databricks/koalas/tests/test_repr.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16+
import numpy as np
17+
1618
from databricks import koalas as ks
1719
from databricks.koalas.config import set_option, reset_option, option_context
1820
from databricks.koalas.testing.utils import ReusedSQLTestCase
@@ -81,3 +83,23 @@ def test_html_repr(self):
8183
with option_context("display.max_rows", None):
8284
kdf = ks.range(ReprTest.max_display_count + 1)
8385
self.assertEqual(kdf._repr_html_(), kdf.to_pandas()._repr_html_())
86+
87+
def test_repr_float_index(self):
88+
kdf = ks.DataFrame({'a': np.random.rand(ReprTest.max_display_count)},
89+
index=np.random.rand(ReprTest.max_display_count))
90+
self.assertTrue("Showing only the first" not in repr(kdf))
91+
self.assert_eq(repr(kdf), repr(kdf.to_pandas()))
92+
self.assertTrue("Showing only the first" not in repr(kdf.a))
93+
self.assert_eq(repr(kdf.a), repr(kdf.a.to_pandas()))
94+
self.assertTrue("Showing only the first" not in repr(kdf.index))
95+
self.assert_eq(repr(kdf.index), repr(kdf.index.to_pandas()))
96+
97+
self.assertTrue("Showing only the first" not in kdf._repr_html_())
98+
self.assertEqual(kdf._repr_html_(), kdf.to_pandas()._repr_html_())
99+
100+
kdf = ks.DataFrame({'a': np.random.rand(ReprTest.max_display_count + 1)},
101+
index=np.random.rand(ReprTest.max_display_count + 1))
102+
self.assertTrue("Showing only the first" in repr(kdf))
103+
self.assertTrue("Showing only the first" in repr(kdf.a))
104+
self.assertTrue("Showing only the first" in repr(kdf.index))
105+
self.assertTrue("Showing only the first" in kdf._repr_html_())

0 commit comments

Comments
 (0)