diff --git a/eland/dataframe.py b/eland/dataframe.py index c724f6e..98d6dab 100644 --- a/eland/dataframe.py +++ b/eland/dataframe.py @@ -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 - _buf.write("\n
{nrows} rows x {ncols} columns
" + _buf.write("\n{nrows} rows × {ncols} columns
" .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) diff --git a/eland/tests/dataframe/test_repr_pytest.py b/eland/tests/dataframe/test_repr_pytest.py index bee457a..691e088 100644 --- a/eland/tests/dataframe/test_repr_pytest.py +++ b/eland/tests/dataframe/test_repr_pytest.py @@ -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 + # 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