Skip to content

STYLE: incondintent namaspace(series) #40159

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 2 commits into from
Mar 2, 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
16 changes: 8 additions & 8 deletions pandas/tests/series/accessors/test_dt_accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def get_expected(s, name):
if isinstance(result, np.ndarray):
if is_integer_dtype(result):
result = result.astype("int64")
elif not is_list_like(result) or isinstance(result, pd.DataFrame):
elif not is_list_like(result) or isinstance(result, DataFrame):
return result
return Series(result, index=s.index, name=s.name)

Expand All @@ -83,7 +83,7 @@ def compare(s, name):
b = get_expected(s, prop)
if not (is_list_like(a) and is_list_like(b)):
assert a == b
elif isinstance(a, pd.DataFrame):
elif isinstance(a, DataFrame):
tm.assert_frame_equal(a, b)
else:
tm.assert_series_equal(a, b)
Expand Down Expand Up @@ -180,7 +180,7 @@ def compare(s, name):
assert result.dtype == object

result = s.dt.total_seconds()
assert isinstance(result, pd.Series)
assert isinstance(result, Series)
assert result.dtype == "float64"

freq_result = s.dt.freq
Expand Down Expand Up @@ -236,11 +236,11 @@ def get_dir(s):

# 11295
# ambiguous time error on the conversions
s = Series(pd.date_range("2015-01-01", "2016-01-01", freq="T"), name="xxx")
s = Series(date_range("2015-01-01", "2016-01-01", freq="T"), name="xxx")
s = s.dt.tz_localize("UTC").dt.tz_convert("America/Chicago")
results = get_dir(s)
tm.assert_almost_equal(results, sorted(set(ok_for_dt + ok_for_dt_methods)))
exp_values = pd.date_range(
exp_values = date_range(
"2015-01-01", "2016-01-01", freq="T", tz="UTC"
).tz_convert("America/Chicago")
# freq not preserved by tz_localize above
Expand Down Expand Up @@ -297,7 +297,7 @@ def test_dt_round_tz(self):
@pytest.mark.parametrize("method", ["ceil", "round", "floor"])
def test_dt_round_tz_ambiguous(self, method):
# GH 18946 round near "fall back" DST
df1 = pd.DataFrame(
df1 = DataFrame(
[
pd.to_datetime("2017-10-29 02:00:00+02:00", utc=True),
pd.to_datetime("2017-10-29 02:00:00+01:00", utc=True),
Expand Down Expand Up @@ -634,7 +634,7 @@ def test_dt_accessor_invalid(self, ser):
assert not hasattr(ser, "dt")

def test_dt_accessor_updates_on_inplace(self):
s = Series(pd.date_range("2018-01-01", periods=10))
s = Series(date_range("2018-01-01", periods=10))
s[2] = None
return_value = s.fillna(pd.Timestamp("2018-01-01"), inplace=True)
assert return_value is None
Expand Down Expand Up @@ -680,7 +680,7 @@ def test_dt_timetz_accessor(self, tz_naive_fixture):
)
def test_isocalendar(self, input_series, expected_output):
result = pd.to_datetime(Series(input_series)).dt.isocalendar()
expected_frame = pd.DataFrame(
expected_frame = DataFrame(
expected_output, columns=["year", "week", "day"], dtype="UInt32"
)
tm.assert_frame_equal(result, expected_frame)
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/series/indexing/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ def test_indexing_over_size_cutoff_period_index(monkeypatch):
monkeypatch.setattr(libindex, "_SIZE_CUTOFF", 1000)

n = 1100
idx = pd.period_range("1/1/2000", freq="T", periods=n)
idx = period_range("1/1/2000", freq="T", periods=n)
assert idx._engine.over_size_threshold

s = Series(np.random.randn(len(idx)), index=idx)
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/series/indexing/test_getitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ def test_getitem_slice_integers(self):


class TestSeriesGetitemListLike:
@pytest.mark.parametrize("box", [list, np.array, Index, pd.Series])
@pytest.mark.parametrize("box", [list, np.array, Index, Series])
def test_getitem_no_matches(self, box):
# GH#33462 we expect the same behavior for list/ndarray/Index/Series
ser = Series(["A", "B"])
Expand Down
7 changes: 3 additions & 4 deletions pandas/tests/series/indexing/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import numpy as np
import pytest

import pandas as pd
from pandas import (
DataFrame,
IndexSlice,
Expand Down Expand Up @@ -58,7 +57,7 @@ def test_basic_getitem_dt64tz_values():
# GH12089
# with tz for values
ser = Series(
pd.date_range("2011-01-01", periods=3, tz="US/Eastern"), index=["a", "b", "c"]
date_range("2011-01-01", periods=3, tz="US/Eastern"), index=["a", "b", "c"]
)
expected = Timestamp("2011-01-01", tz="US/Eastern")
result = ser.loc["a"]
Expand Down Expand Up @@ -114,7 +113,7 @@ def test_getitem_setitem_integers():


def test_series_box_timestamp():
rng = pd.date_range("20090415", "20090519", freq="B")
rng = date_range("20090415", "20090519", freq="B")
ser = Series(rng)
assert isinstance(ser[0], Timestamp)
assert isinstance(ser.at[1], Timestamp)
Expand All @@ -131,7 +130,7 @@ def test_series_box_timestamp():


def test_series_box_timedelta():
rng = pd.timedelta_range("1 day 1 s", periods=5, freq="h")
rng = timedelta_range("1 day 1 s", periods=5, freq="h")
ser = Series(rng)
assert isinstance(ser[0], Timedelta)
assert isinstance(ser.at[1], Timedelta)
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/series/indexing/test_where.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ def test_where_datetimelike_categorical(tz_naive_fixture):
# GH#37682
tz = tz_naive_fixture

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

Expand Down
6 changes: 3 additions & 3 deletions pandas/tests/series/methods/test_interpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ def test_interp_datetime64(self, method, tz_naive_fixture):

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

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

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

index = pd.date_range("1/1/2012", periods=4, freq="12H")
index = date_range("1/1/2012", periods=4, freq="12H")
ts = Series([0, 12, 24, 36], index)
new_index = index.append(index + pd.DateOffset(hours=1)).sort_values()
result = ts.reindex(new_index).interpolate(method="time")
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/series/methods/test_shift.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,14 +353,14 @@ def test_shift_preserve_freqstr(self, periods):
# GH#21275
ser = Series(
range(periods),
index=pd.date_range("2016-1-1 00:00:00", periods=periods, freq="H"),
index=date_range("2016-1-1 00:00:00", periods=periods, freq="H"),
)

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

expected = Series(
range(periods),
index=pd.date_range("2016-1-1 02:00:00", periods=periods, freq="H"),
index=date_range("2016-1-1 02:00:00", periods=periods, freq="H"),
)
tm.assert_series_equal(result, expected)

Expand Down
56 changes: 28 additions & 28 deletions pandas/tests/series/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,16 +689,16 @@ def test_constructor_pass_nan_nat(self):
tm.assert_series_equal(Series([np.nan, np.nan]), exp)
tm.assert_series_equal(Series(np.array([np.nan, np.nan])), exp)

exp = Series([pd.NaT, pd.NaT])
exp = Series([NaT, NaT])
assert exp.dtype == "datetime64[ns]"
tm.assert_series_equal(Series([pd.NaT, pd.NaT]), exp)
tm.assert_series_equal(Series(np.array([pd.NaT, pd.NaT])), exp)
tm.assert_series_equal(Series([NaT, NaT]), exp)
tm.assert_series_equal(Series(np.array([NaT, NaT])), exp)

tm.assert_series_equal(Series([pd.NaT, np.nan]), exp)
tm.assert_series_equal(Series(np.array([pd.NaT, np.nan])), exp)
tm.assert_series_equal(Series([NaT, np.nan]), exp)
tm.assert_series_equal(Series(np.array([NaT, np.nan])), exp)

tm.assert_series_equal(Series([np.nan, pd.NaT]), exp)
tm.assert_series_equal(Series(np.array([np.nan, pd.NaT])), exp)
tm.assert_series_equal(Series([np.nan, NaT]), exp)
tm.assert_series_equal(Series(np.array([np.nan, NaT])), exp)

def test_constructor_cast(self):
msg = "could not convert string to float"
Expand Down Expand Up @@ -824,7 +824,7 @@ def test_constructor_dtype_datetime64(self):
tm.assert_series_equal(result, expected)

expected = Series(
[pd.NaT, datetime(2013, 1, 2), datetime(2013, 1, 3)], dtype="datetime64[ns]"
[NaT, datetime(2013, 1, 2), datetime(2013, 1, 3)], dtype="datetime64[ns]"
)
result = Series([np.nan] + dates[1:], dtype="datetime64[ns]")
tm.assert_series_equal(result, expected)
Expand Down Expand Up @@ -888,13 +888,13 @@ def test_constructor_dtype_datetime64(self):
assert series1.dtype == object

# these will correctly infer a datetime
s = Series([None, pd.NaT, "2013-08-05 15:30:00.000001"])
s = Series([None, NaT, "2013-08-05 15:30:00.000001"])
assert s.dtype == "datetime64[ns]"
s = Series([np.nan, pd.NaT, "2013-08-05 15:30:00.000001"])
s = Series([np.nan, NaT, "2013-08-05 15:30:00.000001"])
assert s.dtype == "datetime64[ns]"
s = Series([pd.NaT, None, "2013-08-05 15:30:00.000001"])
s = Series([NaT, None, "2013-08-05 15:30:00.000001"])
assert s.dtype == "datetime64[ns]"
s = Series([pd.NaT, np.nan, "2013-08-05 15:30:00.000001"])
s = Series([NaT, np.nan, "2013-08-05 15:30:00.000001"])
assert s.dtype == "datetime64[ns]"

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

# non-convertible
s = Series([1479596223000, -1479590, pd.NaT])
s = Series([1479596223000, -1479590, NaT])
assert s.dtype == "object"
assert s[2] is pd.NaT
assert s[2] is NaT
assert "NaT" in str(s)

# if we passed a NaT it remains
s = Series([datetime(2010, 1, 1), datetime(2, 1, 1), pd.NaT])
s = Series([datetime(2010, 1, 1), datetime(2, 1, 1), NaT])
assert s.dtype == "object"
assert s[2] is pd.NaT
assert s[2] is NaT
assert "NaT" in str(s)

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

exp = pd.DatetimeIndex(result)
exp = DatetimeIndex(result)
exp = exp.tz_localize("UTC").tz_convert(tz=s.dt.tz)
tm.assert_index_equal(dr, exp)

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

result = pd.DatetimeIndex(s, freq="infer")
result = DatetimeIndex(s, freq="infer")
tm.assert_index_equal(result, dr)

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

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

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

tm.assert_series_equal(result, expected)

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

td = Series([np.timedelta64(300000000), pd.NaT], dtype="m8[ns]")
td = Series([np.timedelta64(300000000), NaT], dtype="m8[ns]")
assert td.dtype == "timedelta64[ns]"

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

td = Series([pd.NaT, np.timedelta64(300000000)])
td = Series([NaT, np.timedelta64(300000000)])
assert td.dtype == "timedelta64[ns]"

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

# these will correctly infer a timedelta
s = Series([None, pd.NaT, "1 Day"])
s = Series([None, NaT, "1 Day"])
assert s.dtype == "timedelta64[ns]"
s = Series([np.nan, pd.NaT, "1 Day"])
s = Series([np.nan, NaT, "1 Day"])
assert s.dtype == "timedelta64[ns]"
s = Series([pd.NaT, None, "1 Day"])
s = Series([NaT, None, "1 Day"])
assert s.dtype == "timedelta64[ns]"
s = Series([pd.NaT, np.nan, "1 Day"])
s = Series([NaT, np.nan, "1 Day"])
assert s.dtype == "timedelta64[ns]"

# GH 16406
Expand Down Expand Up @@ -1606,7 +1606,7 @@ def test_constructor_dict_multiindex(self):
_d = sorted(d.items())
result = Series(d)
expected = Series(
[x[1] for x in _d], index=pd.MultiIndex.from_tuples([x[0] for x in _d])
[x[1] for x in _d], index=MultiIndex.from_tuples([x[0] for x in _d])
)
tm.assert_series_equal(result, expected)

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/series/test_repr.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def test_repr_should_return_str(self):

def test_repr_max_rows(self):
# GH 6863
with pd.option_context("max_rows", None):
with option_context("max_rows", None):
str(Series(range(1001))) # should not raise exception

def test_unicode_string_with_unicode(self):
Expand Down