Skip to content

Commit fb47a3d

Browse files
authored
STYLE: incondintent namaspace(series) (#40159)
* STYLE: incondintent namaspace(series) * remove import-pandas
1 parent 711fa92 commit fb47a3d

File tree

9 files changed

+48
-49
lines changed

9 files changed

+48
-49
lines changed

pandas/tests/series/accessors/test_dt_accessor.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def get_expected(s, name):
7474
if isinstance(result, np.ndarray):
7575
if is_integer_dtype(result):
7676
result = result.astype("int64")
77-
elif not is_list_like(result) or isinstance(result, pd.DataFrame):
77+
elif not is_list_like(result) or isinstance(result, DataFrame):
7878
return result
7979
return Series(result, index=s.index, name=s.name)
8080

@@ -83,7 +83,7 @@ def compare(s, name):
8383
b = get_expected(s, prop)
8484
if not (is_list_like(a) and is_list_like(b)):
8585
assert a == b
86-
elif isinstance(a, pd.DataFrame):
86+
elif isinstance(a, DataFrame):
8787
tm.assert_frame_equal(a, b)
8888
else:
8989
tm.assert_series_equal(a, b)
@@ -180,7 +180,7 @@ def compare(s, name):
180180
assert result.dtype == object
181181

182182
result = s.dt.total_seconds()
183-
assert isinstance(result, pd.Series)
183+
assert isinstance(result, Series)
184184
assert result.dtype == "float64"
185185

186186
freq_result = s.dt.freq
@@ -236,11 +236,11 @@ def get_dir(s):
236236

237237
# 11295
238238
# ambiguous time error on the conversions
239-
s = Series(pd.date_range("2015-01-01", "2016-01-01", freq="T"), name="xxx")
239+
s = Series(date_range("2015-01-01", "2016-01-01", freq="T"), name="xxx")
240240
s = s.dt.tz_localize("UTC").dt.tz_convert("America/Chicago")
241241
results = get_dir(s)
242242
tm.assert_almost_equal(results, sorted(set(ok_for_dt + ok_for_dt_methods)))
243-
exp_values = pd.date_range(
243+
exp_values = date_range(
244244
"2015-01-01", "2016-01-01", freq="T", tz="UTC"
245245
).tz_convert("America/Chicago")
246246
# freq not preserved by tz_localize above
@@ -297,7 +297,7 @@ def test_dt_round_tz(self):
297297
@pytest.mark.parametrize("method", ["ceil", "round", "floor"])
298298
def test_dt_round_tz_ambiguous(self, method):
299299
# GH 18946 round near "fall back" DST
300-
df1 = pd.DataFrame(
300+
df1 = DataFrame(
301301
[
302302
pd.to_datetime("2017-10-29 02:00:00+02:00", utc=True),
303303
pd.to_datetime("2017-10-29 02:00:00+01:00", utc=True),
@@ -634,7 +634,7 @@ def test_dt_accessor_invalid(self, ser):
634634
assert not hasattr(ser, "dt")
635635

636636
def test_dt_accessor_updates_on_inplace(self):
637-
s = Series(pd.date_range("2018-01-01", periods=10))
637+
s = Series(date_range("2018-01-01", periods=10))
638638
s[2] = None
639639
return_value = s.fillna(pd.Timestamp("2018-01-01"), inplace=True)
640640
assert return_value is None
@@ -680,7 +680,7 @@ def test_dt_timetz_accessor(self, tz_naive_fixture):
680680
)
681681
def test_isocalendar(self, input_series, expected_output):
682682
result = pd.to_datetime(Series(input_series)).dt.isocalendar()
683-
expected_frame = pd.DataFrame(
683+
expected_frame = DataFrame(
684684
expected_output, columns=["year", "week", "day"], dtype="UInt32"
685685
)
686686
tm.assert_frame_equal(result, expected_frame)

pandas/tests/series/indexing/test_datetime.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ def test_indexing_over_size_cutoff_period_index(monkeypatch):
352352
monkeypatch.setattr(libindex, "_SIZE_CUTOFF", 1000)
353353

354354
n = 1100
355-
idx = pd.period_range("1/1/2000", freq="T", periods=n)
355+
idx = period_range("1/1/2000", freq="T", periods=n)
356356
assert idx._engine.over_size_threshold
357357

358358
s = Series(np.random.randn(len(idx)), index=idx)

pandas/tests/series/indexing/test_getitem.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ def test_getitem_slice_integers(self):
309309

310310

311311
class TestSeriesGetitemListLike:
312-
@pytest.mark.parametrize("box", [list, np.array, Index, pd.Series])
312+
@pytest.mark.parametrize("box", [list, np.array, Index, Series])
313313
def test_getitem_no_matches(self, box):
314314
# GH#33462 we expect the same behavior for list/ndarray/Index/Series
315315
ser = Series(["A", "B"])

pandas/tests/series/indexing/test_indexing.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import numpy as np
66
import pytest
77

8-
import pandas as pd
98
from pandas import (
109
DataFrame,
1110
IndexSlice,
@@ -58,7 +57,7 @@ def test_basic_getitem_dt64tz_values():
5857
# GH12089
5958
# with tz for values
6059
ser = Series(
61-
pd.date_range("2011-01-01", periods=3, tz="US/Eastern"), index=["a", "b", "c"]
60+
date_range("2011-01-01", periods=3, tz="US/Eastern"), index=["a", "b", "c"]
6261
)
6362
expected = Timestamp("2011-01-01", tz="US/Eastern")
6463
result = ser.loc["a"]
@@ -114,7 +113,7 @@ def test_getitem_setitem_integers():
114113

115114

116115
def test_series_box_timestamp():
117-
rng = pd.date_range("20090415", "20090519", freq="B")
116+
rng = date_range("20090415", "20090519", freq="B")
118117
ser = Series(rng)
119118
assert isinstance(ser[0], Timestamp)
120119
assert isinstance(ser.at[1], Timestamp)
@@ -131,7 +130,7 @@ def test_series_box_timestamp():
131130

132131

133132
def test_series_box_timedelta():
134-
rng = pd.timedelta_range("1 day 1 s", periods=5, freq="h")
133+
rng = timedelta_range("1 day 1 s", periods=5, freq="h")
135134
ser = Series(rng)
136135
assert isinstance(ser[0], Timedelta)
137136
assert isinstance(ser.at[1], Timedelta)

pandas/tests/series/indexing/test_where.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ def test_where_datetimelike_categorical(tz_naive_fixture):
475475
# GH#37682
476476
tz = tz_naive_fixture
477477

478-
dr = pd.date_range("2001-01-01", periods=3, tz=tz)._with_freq(None)
478+
dr = date_range("2001-01-01", periods=3, tz=tz)._with_freq(None)
479479
lvals = pd.DatetimeIndex([dr[0], dr[1], pd.NaT])
480480
rvals = pd.Categorical([dr[0], pd.NaT, dr[2]])
481481

pandas/tests/series/methods/test_interpolate.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ def test_interp_datetime64(self, method, tz_naive_fixture):
642642

643643
def test_interp_pad_datetime64tz_values(self):
644644
# GH#27628 missing.interpolate_2d should handle datetimetz values
645-
dti = pd.date_range("2015-04-05", periods=3, tz="US/Central")
645+
dti = date_range("2015-04-05", periods=3, tz="US/Central")
646646
ser = Series(dti)
647647
ser[1] = pd.NaT
648648
result = ser.interpolate(method="pad")
@@ -735,13 +735,13 @@ def test_series_interpolate_method_values(self):
735735

736736
def test_series_interpolate_intraday(self):
737737
# #1698
738-
index = pd.date_range("1/1/2012", periods=4, freq="12D")
738+
index = date_range("1/1/2012", periods=4, freq="12D")
739739
ts = Series([0, 12, 24, 36], index)
740740
new_index = index.append(index + pd.DateOffset(days=1)).sort_values()
741741

742742
exp = ts.reindex(new_index).interpolate(method="time")
743743

744-
index = pd.date_range("1/1/2012", periods=4, freq="12H")
744+
index = date_range("1/1/2012", periods=4, freq="12H")
745745
ts = Series([0, 12, 24, 36], index)
746746
new_index = index.append(index + pd.DateOffset(hours=1)).sort_values()
747747
result = ts.reindex(new_index).interpolate(method="time")

pandas/tests/series/methods/test_shift.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,14 +353,14 @@ def test_shift_preserve_freqstr(self, periods):
353353
# GH#21275
354354
ser = Series(
355355
range(periods),
356-
index=pd.date_range("2016-1-1 00:00:00", periods=periods, freq="H"),
356+
index=date_range("2016-1-1 00:00:00", periods=periods, freq="H"),
357357
)
358358

359359
result = ser.shift(1, "2H")
360360

361361
expected = Series(
362362
range(periods),
363-
index=pd.date_range("2016-1-1 02:00:00", periods=periods, freq="H"),
363+
index=date_range("2016-1-1 02:00:00", periods=periods, freq="H"),
364364
)
365365
tm.assert_series_equal(result, expected)
366366

pandas/tests/series/test_constructors.py

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -689,16 +689,16 @@ def test_constructor_pass_nan_nat(self):
689689
tm.assert_series_equal(Series([np.nan, np.nan]), exp)
690690
tm.assert_series_equal(Series(np.array([np.nan, np.nan])), exp)
691691

692-
exp = Series([pd.NaT, pd.NaT])
692+
exp = Series([NaT, NaT])
693693
assert exp.dtype == "datetime64[ns]"
694-
tm.assert_series_equal(Series([pd.NaT, pd.NaT]), exp)
695-
tm.assert_series_equal(Series(np.array([pd.NaT, pd.NaT])), exp)
694+
tm.assert_series_equal(Series([NaT, NaT]), exp)
695+
tm.assert_series_equal(Series(np.array([NaT, NaT])), exp)
696696

697-
tm.assert_series_equal(Series([pd.NaT, np.nan]), exp)
698-
tm.assert_series_equal(Series(np.array([pd.NaT, np.nan])), exp)
697+
tm.assert_series_equal(Series([NaT, np.nan]), exp)
698+
tm.assert_series_equal(Series(np.array([NaT, np.nan])), exp)
699699

700-
tm.assert_series_equal(Series([np.nan, pd.NaT]), exp)
701-
tm.assert_series_equal(Series(np.array([np.nan, pd.NaT])), exp)
700+
tm.assert_series_equal(Series([np.nan, NaT]), exp)
701+
tm.assert_series_equal(Series(np.array([np.nan, NaT])), exp)
702702

703703
def test_constructor_cast(self):
704704
msg = "could not convert string to float"
@@ -824,7 +824,7 @@ def test_constructor_dtype_datetime64(self):
824824
tm.assert_series_equal(result, expected)
825825

826826
expected = Series(
827-
[pd.NaT, datetime(2013, 1, 2), datetime(2013, 1, 3)], dtype="datetime64[ns]"
827+
[NaT, datetime(2013, 1, 2), datetime(2013, 1, 3)], dtype="datetime64[ns]"
828828
)
829829
result = Series([np.nan] + dates[1:], dtype="datetime64[ns]")
830830
tm.assert_series_equal(result, expected)
@@ -888,13 +888,13 @@ def test_constructor_dtype_datetime64(self):
888888
assert series1.dtype == object
889889

890890
# these will correctly infer a datetime
891-
s = Series([None, pd.NaT, "2013-08-05 15:30:00.000001"])
891+
s = Series([None, NaT, "2013-08-05 15:30:00.000001"])
892892
assert s.dtype == "datetime64[ns]"
893-
s = Series([np.nan, pd.NaT, "2013-08-05 15:30:00.000001"])
893+
s = Series([np.nan, NaT, "2013-08-05 15:30:00.000001"])
894894
assert s.dtype == "datetime64[ns]"
895-
s = Series([pd.NaT, None, "2013-08-05 15:30:00.000001"])
895+
s = Series([NaT, None, "2013-08-05 15:30:00.000001"])
896896
assert s.dtype == "datetime64[ns]"
897-
s = Series([pd.NaT, np.nan, "2013-08-05 15:30:00.000001"])
897+
s = Series([NaT, np.nan, "2013-08-05 15:30:00.000001"])
898898
assert s.dtype == "datetime64[ns]"
899899

900900
# tz-aware (UTC and other tz's)
@@ -907,15 +907,15 @@ def test_constructor_dtype_datetime64(self):
907907
assert str(Series(dr).iloc[0].tz) == "US/Eastern"
908908

909909
# non-convertible
910-
s = Series([1479596223000, -1479590, pd.NaT])
910+
s = Series([1479596223000, -1479590, NaT])
911911
assert s.dtype == "object"
912-
assert s[2] is pd.NaT
912+
assert s[2] is NaT
913913
assert "NaT" in str(s)
914914

915915
# if we passed a NaT it remains
916-
s = Series([datetime(2010, 1, 1), datetime(2, 1, 1), pd.NaT])
916+
s = Series([datetime(2010, 1, 1), datetime(2, 1, 1), NaT])
917917
assert s.dtype == "object"
918-
assert s[2] is pd.NaT
918+
assert s[2] is NaT
919919
assert "NaT" in str(s)
920920

921921
# if we passed a nan it remains
@@ -941,7 +941,7 @@ def test_constructor_with_datetime_tz(self):
941941
assert isinstance(result, np.ndarray)
942942
assert result.dtype == "datetime64[ns]"
943943

944-
exp = pd.DatetimeIndex(result)
944+
exp = DatetimeIndex(result)
945945
exp = exp.tz_localize("UTC").tz_convert(tz=s.dt.tz)
946946
tm.assert_index_equal(dr, exp)
947947

@@ -977,7 +977,7 @@ def test_constructor_with_datetime_tz(self):
977977
t = Series(date_range("20130101", periods=1000, tz="US/Eastern"))
978978
assert "datetime64[ns, US/Eastern]" in str(t)
979979

980-
result = pd.DatetimeIndex(s, freq="infer")
980+
result = DatetimeIndex(s, freq="infer")
981981
tm.assert_index_equal(result, dr)
982982

983983
# inference
@@ -1000,8 +1000,8 @@ def test_constructor_with_datetime_tz(self):
10001000
assert lib.infer_dtype(s, skipna=True) == "datetime"
10011001

10021002
# with all NaT
1003-
s = Series(pd.NaT, index=[0, 1], dtype="datetime64[ns, US/Eastern]")
1004-
expected = Series(pd.DatetimeIndex(["NaT", "NaT"], tz="US/Eastern"))
1003+
s = Series(NaT, index=[0, 1], dtype="datetime64[ns, US/Eastern]")
1004+
expected = Series(DatetimeIndex(["NaT", "NaT"], tz="US/Eastern"))
10051005
tm.assert_series_equal(s, expected)
10061006

10071007
@pytest.mark.parametrize("arr_dtype", [np.int64, np.float64])
@@ -1018,7 +1018,7 @@ def test_construction_to_datetimelike_unit(self, arr_dtype, dtype, unit):
10181018

10191019
tm.assert_series_equal(result, expected)
10201020

1021-
@pytest.mark.parametrize("arg", ["2013-01-01 00:00:00", pd.NaT, np.nan, None])
1021+
@pytest.mark.parametrize("arg", ["2013-01-01 00:00:00", NaT, np.nan, None])
10221022
def test_constructor_with_naive_string_and_datetimetz_dtype(self, arg):
10231023
# GH 17415: With naive string
10241024
result = Series([arg], dtype="datetime64[ns, CET]")
@@ -1302,7 +1302,7 @@ def test_constructor_dtype_timedelta64(self):
13021302
td = Series([timedelta(days=1), np.nan], dtype="m8[ns]")
13031303
assert td.dtype == "timedelta64[ns]"
13041304

1305-
td = Series([np.timedelta64(300000000), pd.NaT], dtype="m8[ns]")
1305+
td = Series([np.timedelta64(300000000), NaT], dtype="m8[ns]")
13061306
assert td.dtype == "timedelta64[ns]"
13071307

13081308
# improved inference
@@ -1317,7 +1317,7 @@ def test_constructor_dtype_timedelta64(self):
13171317
td = Series([np.timedelta64(300000000), np.nan])
13181318
assert td.dtype == "timedelta64[ns]"
13191319

1320-
td = Series([pd.NaT, np.timedelta64(300000000)])
1320+
td = Series([NaT, np.timedelta64(300000000)])
13211321
assert td.dtype == "timedelta64[ns]"
13221322

13231323
td = Series([np.timedelta64(1, "s")])
@@ -1349,13 +1349,13 @@ def test_constructor_dtype_timedelta64(self):
13491349
assert td.dtype == "object"
13501350

13511351
# these will correctly infer a timedelta
1352-
s = Series([None, pd.NaT, "1 Day"])
1352+
s = Series([None, NaT, "1 Day"])
13531353
assert s.dtype == "timedelta64[ns]"
1354-
s = Series([np.nan, pd.NaT, "1 Day"])
1354+
s = Series([np.nan, NaT, "1 Day"])
13551355
assert s.dtype == "timedelta64[ns]"
1356-
s = Series([pd.NaT, None, "1 Day"])
1356+
s = Series([NaT, None, "1 Day"])
13571357
assert s.dtype == "timedelta64[ns]"
1358-
s = Series([pd.NaT, np.nan, "1 Day"])
1358+
s = Series([NaT, np.nan, "1 Day"])
13591359
assert s.dtype == "timedelta64[ns]"
13601360

13611361
# GH 16406
@@ -1606,7 +1606,7 @@ def test_constructor_dict_multiindex(self):
16061606
_d = sorted(d.items())
16071607
result = Series(d)
16081608
expected = Series(
1609-
[x[1] for x in _d], index=pd.MultiIndex.from_tuples([x[0] for x in _d])
1609+
[x[1] for x in _d], index=MultiIndex.from_tuples([x[0] for x in _d])
16101610
)
16111611
tm.assert_series_equal(result, expected)
16121612

pandas/tests/series/test_repr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def test_repr_should_return_str(self):
169169

170170
def test_repr_max_rows(self):
171171
# GH 6863
172-
with pd.option_context("max_rows", None):
172+
with option_context("max_rows", None):
173173
str(Series(range(1001))) # should not raise exception
174174

175175
def test_unicode_string_with_unicode(self):

0 commit comments

Comments
 (0)