Skip to content

STYLE: inconsistent namespace (io, reshape) #40069

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pandas/tests/io/excel/test_writers.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def test_read_excel_parse_dates(self, ext):

def test_multiindex_interval_datetimes(self, ext):
# GH 30986
midx = pd.MultiIndex.from_arrays(
midx = MultiIndex.from_arrays(
[
range(4),
pd.interval_range(
Expand All @@ -289,7 +289,7 @@ def test_multiindex_interval_datetimes(self, ext):
result = pd.read_excel(pth, index_col=[0, 1])
expected = DataFrame(
range(4),
pd.MultiIndex.from_arrays(
MultiIndex.from_arrays(
[
range(4),
[
Expand Down
64 changes: 31 additions & 33 deletions pandas/tests/io/formats/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def test_repr_deprecation_negative_int(self):

def test_repr_chop_threshold(self):
df = DataFrame([[0.1, 0.5], [0.5, -0.1]])
pd.reset_option("display.chop_threshold") # default None
reset_option("display.chop_threshold") # default None
assert repr(df) == " 0 1\n0 0.1 0.5\n1 0.5 -0.1"

with option_context("display.chop_threshold", 0.2):
Expand Down Expand Up @@ -382,7 +382,7 @@ def test_repr_truncates_terminal_size(self, monkeypatch):
)

index = range(5)
columns = pd.MultiIndex.from_tuples(
columns = MultiIndex.from_tuples(
[
("This is a long title with > 37 chars.", "cat"),
("This is a loooooonger title with > 43 chars.", "dog"),
Expand Down Expand Up @@ -689,7 +689,7 @@ def test_east_asian_unicode_false(self):
assert repr(df) == expected

# MultiIndex
idx = pd.MultiIndex.from_tuples(
idx = MultiIndex.from_tuples(
[("あ", "いい"), ("う", "え"), ("おおお", "かかかか"), ("き", "くく")]
)
df = DataFrame(
Expand Down Expand Up @@ -833,7 +833,7 @@ def test_east_asian_unicode_true(self):
assert repr(df) == expected

# MultiIndex
idx = pd.MultiIndex.from_tuples(
idx = MultiIndex.from_tuples(
[("あ", "いい"), ("う", "え"), ("おおお", "かかかか"), ("き", "くく")]
)
df = DataFrame(
Expand Down Expand Up @@ -1002,14 +1002,14 @@ def test_truncate_with_different_dtypes(self):
+ [datetime.datetime(2012, 1, 3)] * 10
)

with pd.option_context("display.max_rows", 8):
with option_context("display.max_rows", 8):
result = str(s)
assert "object" in result

# 12045
df = DataFrame({"text": ["some words"] + [None] * 9})

with pd.option_context("display.max_rows", 8, "display.max_columns", 3):
with option_context("display.max_rows", 8, "display.max_columns", 3):
result = str(df)
assert "None" in result
assert "NaN" not in result
Expand All @@ -1026,9 +1026,7 @@ def test_truncate_with_different_dtypes_multiindex(self):
def test_datetimelike_frame(self):

# GH 12211
df = DataFrame(
{"date": [Timestamp("20130101").tz_localize("UTC")] + [pd.NaT] * 5}
)
df = DataFrame({"date": [Timestamp("20130101").tz_localize("UTC")] + [NaT] * 5})

with option_context("display.max_rows", 5):
result = str(df)
Expand All @@ -1037,7 +1035,7 @@ def test_datetimelike_frame(self):
assert "..." in result
assert "[6 rows x 1 columns]" in result

dts = [Timestamp("2011-01-01", tz="US/Eastern")] * 5 + [pd.NaT] * 5
dts = [Timestamp("2011-01-01", tz="US/Eastern")] * 5 + [NaT] * 5
df = DataFrame({"dt": dts, "x": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]})
with option_context("display.max_rows", 5):
expected = (
Expand All @@ -1051,7 +1049,7 @@ def test_datetimelike_frame(self):
)
assert repr(df) == expected

dts = [pd.NaT] * 5 + [Timestamp("2011-01-01", tz="US/Eastern")] * 5
dts = [NaT] * 5 + [Timestamp("2011-01-01", tz="US/Eastern")] * 5
df = DataFrame({"dt": dts, "x": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]})
with option_context("display.max_rows", 5):
expected = (
Expand Down Expand Up @@ -1117,7 +1115,7 @@ def test_unicode_problem_decoding_as_ascii(self):

def test_string_repr_encoding(self, datapath):
filepath = datapath("io", "parser", "data", "unicode_series.csv")
df = pd.read_csv(filepath, header=None, encoding="latin1")
df = read_csv(filepath, header=None, encoding="latin1")
repr(df)
repr(df[1])

Expand Down Expand Up @@ -1548,7 +1546,7 @@ def test_to_string_float_index(self):

def test_to_string_complex_float_formatting(self):
# GH #25514, 25745
with pd.option_context("display.precision", 5):
with option_context("display.precision", 5):
df = DataFrame(
{
"x": [
Expand Down Expand Up @@ -1785,7 +1783,7 @@ def test_repr_html_mathjax(self):
df = DataFrame([[1, 2], [3, 4]])
assert "tex2jax_ignore" not in df._repr_html_()

with pd.option_context("display.html.use_mathjax", False):
with option_context("display.html.use_mathjax", False):
assert "tex2jax_ignore" in df._repr_html_()

def test_repr_html_wide(self):
Expand Down Expand Up @@ -2229,7 +2227,7 @@ def test_east_asian_unicode_series(self):
assert repr(s) == expected

# MultiIndex
idx = pd.MultiIndex.from_tuples(
idx = MultiIndex.from_tuples(
[("あ", "いい"), ("う", "え"), ("おおお", "かかかか"), ("き", "くく")]
)
s = Series([1, 22, 3333, 44444], index=idx)
Expand Down Expand Up @@ -2324,7 +2322,7 @@ def test_east_asian_unicode_series(self):
assert repr(s) == expected

# MultiIndex
idx = pd.MultiIndex.from_tuples(
idx = MultiIndex.from_tuples(
[("あ", "いい"), ("う", "え"), ("おおお", "かかかか"), ("き", "くく")]
)
s = Series([1, 22, 3333, 44444], index=idx)
Expand Down Expand Up @@ -2853,7 +2851,7 @@ def test_output_display_precision_trailing_zeroes(self):
# Issue #20359: trimming zeros while there is no decimal point

# Happens when display precision is set to zero
with pd.option_context("display.precision", 0):
with option_context("display.precision", 0):
s = Series([840.0, 4200.0])
expected_output = "0 840\n1 4200\ndtype: float64"
assert str(s) == expected_output
Expand All @@ -2862,7 +2860,7 @@ def test_output_significant_digits(self):
# Issue #9764

# In case default display precision changes:
with pd.option_context("display.precision", 6):
with option_context("display.precision", 6):
# DataFrame example from issue #9764
d = DataFrame(
{
Expand Down Expand Up @@ -2933,7 +2931,7 @@ def test_output_significant_digits(self):

def test_too_long(self):
# GH 10451
with pd.option_context("display.precision", 4):
with option_context("display.precision", 4):
# need both a number > 1e6 and something that normally formats to
# having length > display.precision + 6
df = DataFrame({"x": [12345.6789]})
Expand Down Expand Up @@ -3011,7 +3009,7 @@ def test_all(self):

class TestTimedelta64Formatter:
def test_days(self):
x = pd.to_timedelta(list(range(5)) + [pd.NaT], unit="D")
x = pd.to_timedelta(list(range(5)) + [NaT], unit="D")
result = fmt.Timedelta64Formatter(x, box=True).get_result()
assert result[0].strip() == "'0 days'"
assert result[1].strip() == "'1 days'"
Expand All @@ -3027,25 +3025,25 @@ def test_days(self):
assert result[0].strip() == "1 days"

def test_days_neg(self):
x = pd.to_timedelta(list(range(5)) + [pd.NaT], unit="D")
x = pd.to_timedelta(list(range(5)) + [NaT], unit="D")
result = fmt.Timedelta64Formatter(-x, box=True).get_result()
assert result[0].strip() == "'0 days'"
assert result[1].strip() == "'-1 days'"

def test_subdays(self):
y = pd.to_timedelta(list(range(5)) + [pd.NaT], unit="s")
y = pd.to_timedelta(list(range(5)) + [NaT], unit="s")
result = fmt.Timedelta64Formatter(y, box=True).get_result()
assert result[0].strip() == "'0 days 00:00:00'"
assert result[1].strip() == "'0 days 00:00:01'"

def test_subdays_neg(self):
y = pd.to_timedelta(list(range(5)) + [pd.NaT], unit="s")
y = pd.to_timedelta(list(range(5)) + [NaT], unit="s")
result = fmt.Timedelta64Formatter(-y, box=True).get_result()
assert result[0].strip() == "'0 days 00:00:00'"
assert result[1].strip() == "'-1 days +23:59:59'"

def test_zero(self):
x = pd.to_timedelta(list(range(1)) + [pd.NaT], unit="D")
x = pd.to_timedelta(list(range(1)) + [NaT], unit="D")
result = fmt.Timedelta64Formatter(x, box=True).get_result()
assert result[0].strip() == "'0 days'"

Expand All @@ -3056,13 +3054,13 @@ def test_zero(self):

class TestDatetime64Formatter:
def test_mixed(self):
x = Series([datetime(2013, 1, 1), datetime(2013, 1, 1, 12), pd.NaT])
x = Series([datetime(2013, 1, 1), datetime(2013, 1, 1, 12), NaT])
result = fmt.Datetime64Formatter(x).get_result()
assert result[0].strip() == "2013-01-01 00:00:00"
assert result[1].strip() == "2013-01-01 12:00:00"

def test_dates(self):
x = Series([datetime(2013, 1, 1), datetime(2013, 1, 2), pd.NaT])
x = Series([datetime(2013, 1, 1), datetime(2013, 1, 2), NaT])
result = fmt.Datetime64Formatter(x).get_result()
assert result[0].strip() == "2013-01-01"
assert result[1].strip() == "2013-01-02"
Expand Down Expand Up @@ -3137,32 +3135,32 @@ def format_func(x):

class TestNaTFormatting:
def test_repr(self):
assert repr(pd.NaT) == "NaT"
assert repr(NaT) == "NaT"

def test_str(self):
assert str(pd.NaT) == "NaT"
assert str(NaT) == "NaT"


class TestDatetimeIndexFormat:
def test_datetime(self):
formatted = pd.to_datetime([datetime(2003, 1, 1, 12), pd.NaT]).format()
formatted = pd.to_datetime([datetime(2003, 1, 1, 12), NaT]).format()
assert formatted[0] == "2003-01-01 12:00:00"
assert formatted[1] == "NaT"

def test_date(self):
formatted = pd.to_datetime([datetime(2003, 1, 1), pd.NaT]).format()
formatted = pd.to_datetime([datetime(2003, 1, 1), NaT]).format()
assert formatted[0] == "2003-01-01"
assert formatted[1] == "NaT"

def test_date_tz(self):
formatted = pd.to_datetime([datetime(2013, 1, 1)], utc=True).format()
assert formatted[0] == "2013-01-01 00:00:00+00:00"

formatted = pd.to_datetime([datetime(2013, 1, 1), pd.NaT], utc=True).format()
formatted = pd.to_datetime([datetime(2013, 1, 1), NaT], utc=True).format()
assert formatted[0] == "2013-01-01 00:00:00+00:00"

def test_date_explicit_date_format(self):
formatted = pd.to_datetime([datetime(2003, 2, 1), pd.NaT]).format(
formatted = pd.to_datetime([datetime(2003, 2, 1), NaT]).format(
date_format="%m-%d-%Y", na_rep="UT"
)
assert formatted[0] == "02-01-2003"
Expand Down Expand Up @@ -3226,7 +3224,7 @@ def test_tz_dateutil(self):

def test_nat_representations(self):
for f in (str, repr, methodcaller("isoformat")):
assert f(pd.NaT) == "NaT"
assert f(NaT) == "NaT"


def test_format_percentiles():
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/io/formats/test_to_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ def test_to_csv_multi_index(self):
),
],
)
@pytest.mark.parametrize("klass", [pd.DataFrame, pd.Series])
@pytest.mark.parametrize("klass", [DataFrame, pd.Series])
def test_to_csv_single_level_multi_index(self, ind, expected, klass):
# see gh-19589
result = klass(pd.Series([1], ind, name="data")).to_csv(
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/io/formats/test_to_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ def test_to_html_render_links(render_links, expected, datapath):
def test_ignore_display_max_colwidth(method, expected, max_colwidth):
# see gh-17004
df = DataFrame([lorem_ipsum])
with pd.option_context("display.max_colwidth", max_colwidth):
with option_context("display.max_colwidth", max_colwidth):
result = getattr(df, method)()
expected = expected(max_colwidth)
assert expected in result
Expand All @@ -782,7 +782,7 @@ def test_to_html_invalid_classes_type(classes):
def test_to_html_round_column_headers():
# GH 17280
df = DataFrame([1], columns=[0.55555])
with pd.option_context("display.precision", 3):
with option_context("display.precision", 3):
html = df.to_html(notebook=False)
notebook = df.to_html(notebook=True)
assert "0.55555" in html
Expand Down
Loading