Skip to content

Commit 3048a86

Browse files
committed
STYLE: inconsistent namespace (io)
1 parent 859a787 commit 3048a86

21 files changed

+137
-161
lines changed

pandas/tests/io/excel/test_writers.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ def test_read_excel_parse_dates(self, ext):
275275

276276
def test_multiindex_interval_datetimes(self, ext):
277277
# GH 30986
278-
midx = pd.MultiIndex.from_arrays(
278+
midx = MultiIndex.from_arrays(
279279
[
280280
range(4),
281281
pd.interval_range(
@@ -289,7 +289,7 @@ def test_multiindex_interval_datetimes(self, ext):
289289
result = pd.read_excel(pth, index_col=[0, 1])
290290
expected = DataFrame(
291291
range(4),
292-
pd.MultiIndex.from_arrays(
292+
MultiIndex.from_arrays(
293293
[
294294
range(4),
295295
[

pandas/tests/io/formats/test_format.py

+31-33
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ def test_repr_deprecation_negative_int(self):
249249

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

255255
with option_context("display.chop_threshold", 0.2):
@@ -382,7 +382,7 @@ def test_repr_truncates_terminal_size(self, monkeypatch):
382382
)
383383

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

691691
# MultiIndex
692-
idx = pd.MultiIndex.from_tuples(
692+
idx = MultiIndex.from_tuples(
693693
[("あ", "いい"), ("う", "え"), ("おおお", "かかかか"), ("き", "くく")]
694694
)
695695
df = DataFrame(
@@ -833,7 +833,7 @@ def test_east_asian_unicode_true(self):
833833
assert repr(df) == expected
834834

835835
# MultiIndex
836-
idx = pd.MultiIndex.from_tuples(
836+
idx = MultiIndex.from_tuples(
837837
[("あ", "いい"), ("う", "え"), ("おおお", "かかかか"), ("き", "くく")]
838838
)
839839
df = DataFrame(
@@ -1002,14 +1002,14 @@ def test_truncate_with_different_dtypes(self):
10021002
+ [datetime.datetime(2012, 1, 3)] * 10
10031003
)
10041004

1005-
with pd.option_context("display.max_rows", 8):
1005+
with option_context("display.max_rows", 8):
10061006
result = str(s)
10071007
assert "object" in result
10081008

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

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

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

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

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

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

11181116
def test_string_repr_encoding(self, datapath):
11191117
filepath = datapath("io", "parser", "data", "unicode_series.csv")
1120-
df = pd.read_csv(filepath, header=None, encoding="latin1")
1118+
df = read_csv(filepath, header=None, encoding="latin1")
11211119
repr(df)
11221120
repr(df[1])
11231121

@@ -1548,7 +1546,7 @@ def test_to_string_float_index(self):
15481546

15491547
def test_to_string_complex_float_formatting(self):
15501548
# GH #25514, 25745
1551-
with pd.option_context("display.precision", 5):
1549+
with option_context("display.precision", 5):
15521550
df = DataFrame(
15531551
{
15541552
"x": [
@@ -1785,7 +1783,7 @@ def test_repr_html_mathjax(self):
17851783
df = DataFrame([[1, 2], [3, 4]])
17861784
assert "tex2jax_ignore" not in df._repr_html_()
17871785

1788-
with pd.option_context("display.html.use_mathjax", False):
1786+
with option_context("display.html.use_mathjax", False):
17891787
assert "tex2jax_ignore" in df._repr_html_()
17901788

17911789
def test_repr_html_wide(self):
@@ -2229,7 +2227,7 @@ def test_east_asian_unicode_series(self):
22292227
assert repr(s) == expected
22302228

22312229
# MultiIndex
2232-
idx = pd.MultiIndex.from_tuples(
2230+
idx = MultiIndex.from_tuples(
22332231
[("あ", "いい"), ("う", "え"), ("おおお", "かかかか"), ("き", "くく")]
22342232
)
22352233
s = Series([1, 22, 3333, 44444], index=idx)
@@ -2324,7 +2322,7 @@ def test_east_asian_unicode_series(self):
23242322
assert repr(s) == expected
23252323

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

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

28642862
# In case default display precision changes:
2865-
with pd.option_context("display.precision", 6):
2863+
with option_context("display.precision", 6):
28662864
# DataFrame example from issue #9764
28672865
d = DataFrame(
28682866
{
@@ -2933,7 +2931,7 @@ def test_output_significant_digits(self):
29332931

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

30123010
class TestTimedelta64Formatter:
30133011
def test_days(self):
3014-
x = pd.to_timedelta(list(range(5)) + [pd.NaT], unit="D")
3012+
x = pd.to_timedelta(list(range(5)) + [NaT], unit="D")
30153013
result = fmt.Timedelta64Formatter(x, box=True).get_result()
30163014
assert result[0].strip() == "'0 days'"
30173015
assert result[1].strip() == "'1 days'"
@@ -3027,25 +3025,25 @@ def test_days(self):
30273025
assert result[0].strip() == "1 days"
30283026

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

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

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

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

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

30573055
class TestDatetime64Formatter:
30583056
def test_mixed(self):
3059-
x = Series([datetime(2013, 1, 1), datetime(2013, 1, 1, 12), pd.NaT])
3057+
x = Series([datetime(2013, 1, 1), datetime(2013, 1, 1, 12), NaT])
30603058
result = fmt.Datetime64Formatter(x).get_result()
30613059
assert result[0].strip() == "2013-01-01 00:00:00"
30623060
assert result[1].strip() == "2013-01-01 12:00:00"
30633061

30643062
def test_dates(self):
3065-
x = Series([datetime(2013, 1, 1), datetime(2013, 1, 2), pd.NaT])
3063+
x = Series([datetime(2013, 1, 1), datetime(2013, 1, 2), NaT])
30663064
result = fmt.Datetime64Formatter(x).get_result()
30673065
assert result[0].strip() == "2013-01-01"
30683066
assert result[1].strip() == "2013-01-02"
@@ -3137,32 +3135,32 @@ def format_func(x):
31373135

31383136
class TestNaTFormatting:
31393137
def test_repr(self):
3140-
assert repr(pd.NaT) == "NaT"
3138+
assert repr(NaT) == "NaT"
31413139

31423140
def test_str(self):
3143-
assert str(pd.NaT) == "NaT"
3141+
assert str(NaT) == "NaT"
31443142

31453143

31463144
class TestDatetimeIndexFormat:
31473145
def test_datetime(self):
3148-
formatted = pd.to_datetime([datetime(2003, 1, 1, 12), pd.NaT]).format()
3146+
formatted = pd.to_datetime([datetime(2003, 1, 1, 12), NaT]).format()
31493147
assert formatted[0] == "2003-01-01 12:00:00"
31503148
assert formatted[1] == "NaT"
31513149

31523150
def test_date(self):
3153-
formatted = pd.to_datetime([datetime(2003, 1, 1), pd.NaT]).format()
3151+
formatted = pd.to_datetime([datetime(2003, 1, 1), NaT]).format()
31543152
assert formatted[0] == "2003-01-01"
31553153
assert formatted[1] == "NaT"
31563154

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

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

31643162
def test_date_explicit_date_format(self):
3165-
formatted = pd.to_datetime([datetime(2003, 2, 1), pd.NaT]).format(
3163+
formatted = pd.to_datetime([datetime(2003, 2, 1), NaT]).format(
31663164
date_format="%m-%d-%Y", na_rep="UT"
31673165
)
31683166
assert formatted[0] == "02-01-2003"
@@ -3226,7 +3224,7 @@ def test_tz_dateutil(self):
32263224

32273225
def test_nat_representations(self):
32283226
for f in (str, repr, methodcaller("isoformat")):
3229-
assert f(pd.NaT) == "NaT"
3227+
assert f(NaT) == "NaT"
32303228

32313229

32323230
def test_format_percentiles():

pandas/tests/io/formats/test_to_csv.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ def test_to_csv_multi_index(self):
326326
),
327327
],
328328
)
329-
@pytest.mark.parametrize("klass", [pd.DataFrame, pd.Series])
329+
@pytest.mark.parametrize("klass", [DataFrame, pd.Series])
330330
def test_to_csv_single_level_multi_index(self, ind, expected, klass):
331331
# see gh-19589
332332
result = klass(pd.Series([1], ind, name="data")).to_csv(

pandas/tests/io/formats/test_to_html.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ def test_to_html_render_links(render_links, expected, datapath):
763763
def test_ignore_display_max_colwidth(method, expected, max_colwidth):
764764
# see gh-17004
765765
df = DataFrame([lorem_ipsum])
766-
with pd.option_context("display.max_colwidth", max_colwidth):
766+
with option_context("display.max_colwidth", max_colwidth):
767767
result = getattr(df, method)()
768768
expected = expected(max_colwidth)
769769
assert expected in result
@@ -782,7 +782,7 @@ def test_to_html_invalid_classes_type(classes):
782782
def test_to_html_round_column_headers():
783783
# GH 17280
784784
df = DataFrame([1], columns=[0.55555])
785-
with pd.option_context("display.precision", 3):
785+
with option_context("display.precision", 3):
786786
html = df.to_html(notebook=False)
787787
notebook = df.to_html(notebook=True)
788788
assert "0.55555" in html

0 commit comments

Comments
 (0)