Add support for pd.set_option("display.max_rows", None)

This commit is contained in:
P. Sai Vinay 2020-11-06 23:53:09 +05:30 committed by GitHub
parent 75451f1e93
commit 789f8959bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 53 additions and 10 deletions

View File

@ -482,7 +482,7 @@ class DataFrame(NDFrame):
max_cols = pd.get_option("display.max_columns")
min_rows = pd.get_option("display.min_rows")
if len(self) > max_rows:
if max_rows and len(self) > max_rows:
max_rows = min_rows
show_dimensions = pd.get_option("display.show_dimensions")
@ -528,7 +528,7 @@ class DataFrame(NDFrame):
min_rows = pd.get_option("display.min_rows")
show_dimensions = pd.get_option("display.show_dimensions")
if len(self) > max_rows:
if max_rows and len(self) > max_rows:
max_rows = min_rows
return self.to_html(

View File

@ -321,7 +321,7 @@ class Series(NDFrame):
max_rows = pd.get_option("display.max_rows")
min_rows = pd.get_option("display.min_rows")
if len(self) > max_rows:
if max_rows and len(self) > max_rows:
max_rows = min_rows
show_dimensions = pd.get_option("display.show_dimensions")

View File

@ -75,7 +75,7 @@ class TestData:
return _ed_ecommerce
def assert_pandas_eland_frame_equal(left, right):
def assert_pandas_eland_frame_equal(left, right, **kwargs):
if not isinstance(left, pd.DataFrame):
raise AssertionError(f"Expected type pd.DataFrame, found {type(left)} instead")
@ -83,10 +83,10 @@ def assert_pandas_eland_frame_equal(left, right):
raise AssertionError(f"Expected type ed.DataFrame, found {type(right)} instead")
# Use pandas tests to check similarity
assert_frame_equal(left, right.to_pandas())
assert_frame_equal(left, right.to_pandas(), **kwargs)
def assert_eland_frame_equal(left, right):
def assert_eland_frame_equal(left, right, **kwargs):
if not isinstance(left, ed.DataFrame):
raise AssertionError(f"Expected type ed.DataFrame, found {type(left)} instead")
@ -94,10 +94,10 @@ def assert_eland_frame_equal(left, right):
raise AssertionError(f"Expected type ed.DataFrame, found {type(right)} instead")
# Use pandas tests to check similarity
assert_frame_equal(left.to_pandas(), right.to_pandas())
assert_frame_equal(left.to_pandas(), right.to_pandas(), **kwargs)
def assert_pandas_eland_series_equal(left, right, check_less_precise=False):
def assert_pandas_eland_series_equal(left, right, **kwargs):
if not isinstance(left, pd.Series):
raise AssertionError(f"Expected type pd.Series, found {type(left)} instead")
@ -105,4 +105,4 @@ def assert_pandas_eland_series_equal(left, right, check_less_precise=False):
raise AssertionError(f"Expected type ed.Series, found {type(right)} instead")
# Use pandas tests to check similarity
assert_series_equal(left, right.to_pandas(), check_less_precise=check_less_precise)
assert_series_equal(left, right.to_pandas(), **kwargs)

View File

@ -72,7 +72,9 @@ class TestDataFrameRepr(TestData):
pd_dest_location = self.pd_flights()["DestLocation"].head(1)
ed_dest_location = self.ed_flights()["DestLocation"].head(1)
assert_pandas_eland_series_equal(pd_dest_location, ed_dest_location)
assert_pandas_eland_series_equal(
pd_dest_location, ed_dest_location, check_exact=False, rtol=2
)
def test_num_rows_to_string(self):
# check setup works
@ -267,3 +269,27 @@ class TestDataFrameRepr(TestData):
pd.set_option("display.show_dimensions", show_dimensions)
assert ed_ecom_rh == pd_ecom_rh
def test_dataframe_repr_pd_get_option_none(self):
show_dimensions = pd.get_option("display.show_dimensions")
show_rows = pd.get_option("display.max_rows")
try:
pd.set_option("display.show_dimensions", False)
pd.set_option("display.max_rows", None)
columns = [
"AvgTicketPrice",
"Cancelled",
"dayOfWeek",
"timestamp",
"DestCountry",
]
ed_flights = self.ed_flights().filter(columns).head(40).__repr__()
pd_flights = self.pd_flights().filter(columns).head(40).__repr__()
assert ed_flights == pd_flights
finally:
# Restore default
pd.set_option("display.max_rows", show_rows)
pd.set_option("display.show_dimensions", show_dimensions)

View File

@ -16,6 +16,8 @@
# under the License.
# File called _pytest for PyCharm compatability
import pandas as pd
import eland as ed
from eland.tests import ES_TEST_CLIENT, FLIGHTS_INDEX_NAME
from eland.tests.common import TestData
@ -44,3 +46,18 @@ class TestSeriesRepr(TestData):
pd_s = self.pd_flights()["Carrier"].head(0)
ed_s = ed.Series(ES_TEST_CLIENT, FLIGHTS_INDEX_NAME, "Carrier").head(0)
assert repr(pd_s) == repr(ed_s)
def test_series_repr_pd_get_option_none(self):
show_dimensions = pd.get_option("display.show_dimensions")
show_rows = pd.get_option("display.max_rows")
try:
pd.set_option("display.show_dimensions", False)
pd.set_option("display.max_rows", None)
ed_flights = self.ed_flights()["Cancelled"].head(40).__repr__()
pd_flights = self.pd_flights()["Cancelled"].head(40).__repr__()
assert ed_flights == pd_flights
finally:
pd.set_option("display.max_rows", show_rows)
pd.set_option("display.show_dimensions", show_dimensions)