mirror of
https://github.com/elastic/eland.git
synced 2025-07-11 00:02:14 +08:00
Merge pull request #57 from blaklaybul/fix-no-results
Adds Proper DataFrame Formatting when max_rows = 0
This commit is contained in:
commit
29b6a70995
@ -580,6 +580,11 @@ class DataFrame(NDFrame):
|
||||
UserWarning)
|
||||
max_rows = DEFAULT_NUM_ROWS_DISPLAYED
|
||||
|
||||
# because of the way pandas handles max_rows=0, not having this throws an error
|
||||
# see eland issue #56
|
||||
if max_rows == 0:
|
||||
max_rows = 1
|
||||
|
||||
# Create a slightly bigger dataframe than display
|
||||
df = self._build_repr_df(max_rows + 1, max_cols)
|
||||
|
||||
@ -600,7 +605,7 @@ class DataFrame(NDFrame):
|
||||
if show_dimensions:
|
||||
# TODO - this results in different output to pandas
|
||||
# TODO - the 'x' character is different and this gets added after the </div>
|
||||
_buf.write("\n<p>{nrows} rows x {ncols} columns</p>"
|
||||
_buf.write("\n<p>{nrows} rows × {ncols} columns</p>"
|
||||
.format(nrows=len(self.index), ncols=len(self.columns)))
|
||||
|
||||
if buf is None:
|
||||
@ -640,6 +645,11 @@ class DataFrame(NDFrame):
|
||||
UserWarning)
|
||||
max_rows = DEFAULT_NUM_ROWS_DISPLAYED
|
||||
|
||||
# because of the way pandas handles max_rows=0, not having this throws an error
|
||||
# see eland issue #56
|
||||
if max_rows == 0:
|
||||
max_rows = 1
|
||||
|
||||
# Create a slightly bigger dataframe than display
|
||||
df = self._build_repr_df(max_rows + 1, max_cols)
|
||||
|
||||
|
@ -52,6 +52,15 @@ class TestDataFrameRepr(TestData):
|
||||
|
||||
assert pd_head_str == ed_head_str
|
||||
|
||||
def test_empty_dataframe_string(self):
|
||||
ed_ecom = self.ed_ecommerce()
|
||||
pd_ecom = self.pd_ecommerce()
|
||||
|
||||
ed_ecom_s = ed_ecom[ed_ecom['currency'] == 'USD'].to_string()
|
||||
pd_ecom_s = pd_ecom[pd_ecom['currency'] == 'USD'].to_string()
|
||||
|
||||
assert ed_ecom_s == pd_ecom_s
|
||||
|
||||
"""
|
||||
repr
|
||||
"""
|
||||
@ -82,8 +91,17 @@ class TestDataFrameRepr(TestData):
|
||||
|
||||
assert pd_head_str == ed_head_str
|
||||
|
||||
def test_empty_dataframe_repr(self):
|
||||
ed_ecom = self.ed_ecommerce()
|
||||
pd_ecom = self.pd_ecommerce()
|
||||
|
||||
ed_ecom_r = repr(ed_ecom[ed_ecom['currency'] == 'USD'])
|
||||
pd_ecom_r = repr(pd_ecom[pd_ecom['currency'] == 'USD'])
|
||||
|
||||
assert ed_ecom_r == pd_ecom_r
|
||||
|
||||
"""
|
||||
to_html
|
||||
to_html
|
||||
"""
|
||||
def test_num_rows_to_html(self):
|
||||
# check setup works
|
||||
@ -118,6 +136,15 @@ class TestDataFrameRepr(TestData):
|
||||
|
||||
assert pd_head_str == ed_head_str
|
||||
|
||||
def test_empty_dataframe_to_html(self):
|
||||
ed_ecom = self.ed_ecommerce()
|
||||
pd_ecom = self.pd_ecommerce()
|
||||
|
||||
ed_ecom_h = ed_ecom[ed_ecom['currency'] == 'USD'].to_html()
|
||||
pd_ecom_h = pd_ecom[pd_ecom['currency'] == 'USD'].to_html()
|
||||
|
||||
assert ed_ecom_h == pd_ecom_h
|
||||
|
||||
|
||||
"""
|
||||
_repr_html_
|
||||
@ -157,3 +184,21 @@ class TestDataFrameRepr(TestData):
|
||||
#print(pd_head_str)
|
||||
|
||||
assert pd_head_str == ed_head_str
|
||||
|
||||
def test_empty_dataframe_repr_html(self):
|
||||
|
||||
# TODO - there is a bug in 'show_dimensions' as it gets added after the last </div>
|
||||
# For now test without this
|
||||
show_dimensions = pd.get_option('display.show_dimensions')
|
||||
pd.set_option('display.show_dimensions', False)
|
||||
|
||||
ed_ecom = self.ed_ecommerce()
|
||||
pd_ecom = self.pd_ecommerce()
|
||||
|
||||
ed_ecom_rh = ed_ecom[ed_ecom['currency'] == 'USD']._repr_html_()
|
||||
pd_ecom_rh = pd_ecom[pd_ecom['currency'] == 'USD']._repr_html_()
|
||||
|
||||
# Restore default
|
||||
pd.set_option('display.show_dimensions', show_dimensions)
|
||||
|
||||
assert ed_ecom_rh == pd_ecom_rh
|
||||
|
Loading…
x
Reference in New Issue
Block a user