Skip to content

CLN: inconsistent namespace usage in tests.indexes #38076

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
Nov 26, 2020
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
6 changes: 3 additions & 3 deletions pandas/tests/indexes/datetimes/test_astype.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def test_astype_object(self):

@pytest.mark.parametrize("tz", [None, "Asia/Tokyo"])
def test_astype_object_tz(self, tz):
idx = pd.date_range(start="2013-01-01", periods=4, freq="M", name="idx", tz=tz)
idx = date_range(start="2013-01-01", periods=4, freq="M", name="idx", tz=tz)
expected_list = [
Timestamp("2013-01-31", tz=tz),
Timestamp("2013-02-28", tz=tz),
Expand Down Expand Up @@ -288,7 +288,7 @@ def test_dti_astype_period(self):
class TestAstype:
@pytest.mark.parametrize("tz", [None, "US/Central"])
def test_astype_category(self, tz):
obj = pd.date_range("2000", periods=2, tz=tz, name="idx")
obj = date_range("2000", periods=2, tz=tz, name="idx")
result = obj.astype("category")
expected = pd.CategoricalIndex(
[Timestamp("2000-01-01", tz=tz), Timestamp("2000-01-02", tz=tz)],
Expand All @@ -302,7 +302,7 @@ def test_astype_category(self, tz):

@pytest.mark.parametrize("tz", [None, "US/Central"])
def test_astype_array_fallback(self, tz):
obj = pd.date_range("2000", periods=2, tz=tz, name="idx")
obj = date_range("2000", periods=2, tz=tz, name="idx")
result = obj.astype(bool)
expected = Index(np.array([True, True]), name="idx")
tm.assert_index_equal(result, expected)
Expand Down
22 changes: 11 additions & 11 deletions pandas/tests/indexes/datetimes/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_freq_validation_with_nat(self, dt_cls):
@pytest.mark.parametrize(
"index",
[
pd.date_range("2016-01-01", periods=5, tz="US/Pacific"),
date_range("2016-01-01", periods=5, tz="US/Pacific"),
pd.timedelta_range("1 Day", periods=5),
],
)
Expand Down Expand Up @@ -103,14 +103,14 @@ def test_construction_caching(self):

df = pd.DataFrame(
{
"dt": pd.date_range("20130101", periods=3),
"dttz": pd.date_range("20130101", periods=3, tz="US/Eastern"),
"dt": date_range("20130101", periods=3),
"dttz": date_range("20130101", periods=3, tz="US/Eastern"),
"dt_with_null": [
Timestamp("20130101"),
pd.NaT,
Timestamp("20130103"),
],
"dtns": pd.date_range("20130101", periods=3, freq="ns"),
"dtns": date_range("20130101", periods=3, freq="ns"),
}
)
assert df.dttz.dtype.tz.zone == "US/Eastern"
Expand All @@ -121,7 +121,7 @@ def test_construction_caching(self):
)
def test_construction_with_alt(self, kwargs, tz_aware_fixture):
tz = tz_aware_fixture
i = pd.date_range("20130101", periods=5, freq="H", tz=tz)
i = date_range("20130101", periods=5, freq="H", tz=tz)
kwargs = {key: attrgetter(val)(i) for key, val in kwargs.items()}
result = DatetimeIndex(i, **kwargs)
tm.assert_index_equal(i, result)
Expand All @@ -132,7 +132,7 @@ def test_construction_with_alt(self, kwargs, tz_aware_fixture):
)
def test_construction_with_alt_tz_localize(self, kwargs, tz_aware_fixture):
tz = tz_aware_fixture
i = pd.date_range("20130101", periods=5, freq="H", tz=tz)
i = date_range("20130101", periods=5, freq="H", tz=tz)
i = i._with_freq(None)
kwargs = {key: attrgetter(val)(i) for key, val in kwargs.items()}

Expand Down Expand Up @@ -754,7 +754,7 @@ def test_construction_int_rountrip(self, tz_naive_fixture):

def test_construction_from_replaced_timestamps_with_dst(self):
# GH 18785
index = pd.date_range(
index = date_range(
Timestamp(2000, 1, 1),
Timestamp(2005, 1, 1),
freq="MS",
Expand Down Expand Up @@ -804,15 +804,15 @@ def test_constructor_with_ambiguous_keyword_arg(self):
start = Timestamp(year=2020, month=11, day=1, hour=1).tz_localize(
timezone, ambiguous=False
)
result = pd.date_range(start=start, periods=2, ambiguous=False)
result = date_range(start=start, periods=2, ambiguous=False)
tm.assert_index_equal(result, expected)

# ambiguous keyword in end
timezone = "America/New_York"
end = Timestamp(year=2020, month=11, day=2, hour=1).tz_localize(
timezone, ambiguous=False
)
result = pd.date_range(end=end, periods=2, ambiguous=False)
result = date_range(end=end, periods=2, ambiguous=False)
tm.assert_index_equal(result, expected)

def test_constructor_with_nonexistent_keyword_arg(self):
Expand All @@ -824,7 +824,7 @@ def test_constructor_with_nonexistent_keyword_arg(self):
start = Timestamp("2015-03-29 02:30:00").tz_localize(
timezone, nonexistent="shift_forward"
)
result = pd.date_range(start=start, periods=2, freq="H")
result = date_range(start=start, periods=2, freq="H")
expected = DatetimeIndex(
[
Timestamp("2015-03-29 03:00:00+02:00", tz=timezone),
Expand All @@ -838,7 +838,7 @@ def test_constructor_with_nonexistent_keyword_arg(self):
end = Timestamp("2015-03-29 02:30:00").tz_localize(
timezone, nonexistent="shift_forward"
)
result = pd.date_range(end=end, periods=2, freq="H")
result = date_range(end=end, periods=2, freq="H")
expected = DatetimeIndex(
[
Timestamp("2015-03-29 01:00:00+01:00", tz=timezone),
Expand Down
28 changes: 14 additions & 14 deletions pandas/tests/indexes/datetimes/test_date_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,10 +650,10 @@ def test_timezone_comparaison_assert(self):
def test_negative_non_tick_frequency_descending_dates(self, tz_aware_fixture):
# GH 23270
tz = tz_aware_fixture
result = pd.date_range(start="2011-06-01", end="2011-01-01", freq="-1MS", tz=tz)
expected = pd.date_range(
end="2011-06-01", start="2011-01-01", freq="1MS", tz=tz
)[::-1]
result = date_range(start="2011-06-01", end="2011-01-01", freq="-1MS", tz=tz)
expected = date_range(end="2011-06-01", start="2011-01-01", freq="1MS", tz=tz)[
::-1
]
tm.assert_index_equal(result, expected)


Expand Down Expand Up @@ -739,10 +739,10 @@ def test_3(self):

def test_precision_finer_than_offset(self):
# GH#9907
result1 = pd.date_range(
result1 = date_range(
start="2015-04-15 00:00:03", end="2016-04-22 00:00:00", freq="Q"
)
result2 = pd.date_range(
result2 = date_range(
start="2015-04-15 00:00:03", end="2015-06-22 00:00:04", freq="W"
)
expected1_list = [
Expand Down Expand Up @@ -788,9 +788,9 @@ def test_mismatching_tz_raises_err(self, start, end):
# issue 18488
msg = "Start and end cannot both be tz-aware with different timezones"
with pytest.raises(TypeError, match=msg):
pd.date_range(start, end)
date_range(start, end)
with pytest.raises(TypeError, match=msg):
pd.date_range(start, end, freq=BDay())
date_range(start, end, freq=BDay())


class TestBusinessDateRange:
Expand Down Expand Up @@ -849,18 +849,18 @@ def test_bdays_and_open_boundaries(self, closed):
# GH 6673
start = "2018-07-21" # Saturday
end = "2018-07-29" # Sunday
result = pd.date_range(start, end, freq="B", closed=closed)
result = date_range(start, end, freq="B", closed=closed)

bday_start = "2018-07-23" # Monday
bday_end = "2018-07-27" # Friday
expected = pd.date_range(bday_start, bday_end, freq="D")
expected = date_range(bday_start, bday_end, freq="D")
tm.assert_index_equal(result, expected)
# Note: we do _not_ expect the freqs to match here

def test_bday_near_overflow(self):
# GH#24252 avoid doing unnecessary addition that _would_ overflow
start = Timestamp.max.floor("D").to_pydatetime()
rng = pd.date_range(start, end=None, periods=1, freq="B")
rng = date_range(start, end=None, periods=1, freq="B")
expected = DatetimeIndex([start], freq="B")
tm.assert_index_equal(rng, expected)

Expand All @@ -869,7 +869,7 @@ def test_bday_overflow_error(self):
msg = "Out of bounds nanosecond timestamp"
start = Timestamp.max.floor("D").to_pydatetime()
with pytest.raises(OutOfBoundsDatetime, match=msg):
pd.date_range(start, periods=2, freq="B")
date_range(start, periods=2, freq="B")


class TestCustomDateRange:
Expand Down Expand Up @@ -995,15 +995,15 @@ def test_all_custom_freq(self, freq):
def test_range_with_millisecond_resolution(self, start_end):
# https://github.com/pandas-dev/pandas/issues/24110
start, end = start_end
result = pd.date_range(start=start, end=end, periods=2, closed="left")
result = date_range(start=start, end=end, periods=2, closed="left")
expected = DatetimeIndex([start])
tm.assert_index_equal(result, expected)


def test_date_range_with_custom_holidays():
# GH 30593
freq = pd.offsets.CustomBusinessHour(start="15:00", holidays=["2020-11-26"])
result = pd.date_range(start="2020-11-25 15:00", periods=4, freq=freq)
result = date_range(start="2020-11-25 15:00", periods=4, freq=freq)
expected = DatetimeIndex(
[
"2020-11-25 15:00:00",
Expand Down
20 changes: 10 additions & 10 deletions pandas/tests/indexes/datetimes/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def test_time_loc(self): # GH8667
step = 24 * 3600

for n in ns:
idx = pd.date_range("2014-11-26", periods=n, freq="S")
idx = date_range("2014-11-26", periods=n, freq="S")
ts = pd.Series(np.random.randn(n), index=idx)
i = np.arange(start, n, step)

Expand All @@ -89,10 +89,10 @@ def test_time_overflow_for_32bit_machines(self):
# overflow.
periods = np.int_(1000)

idx1 = pd.date_range(start="2000", periods=periods, freq="S")
idx1 = date_range(start="2000", periods=periods, freq="S")
assert len(idx1) == periods

idx2 = pd.date_range(end="2000", periods=periods, freq="S")
idx2 = date_range(end="2000", periods=periods, freq="S")
assert len(idx2) == periods

def test_nat(self):
Expand Down Expand Up @@ -251,7 +251,7 @@ def test_ns_index(self):
index = DatetimeIndex(dt, freq=freq, name="time")
self.assert_index_parameters(index)

new_index = pd.date_range(start=index[0], end=index[-1], freq=index.freq)
new_index = date_range(start=index[0], end=index[-1], freq=index.freq)
self.assert_index_parameters(new_index)

def test_factorize(self):
Expand Down Expand Up @@ -304,7 +304,7 @@ def test_factorize(self):
def test_factorize_tz(self, tz_naive_fixture):
tz = tz_naive_fixture
# GH#13750
base = pd.date_range("2016-11-05", freq="H", periods=100, tz=tz)
base = date_range("2016-11-05", freq="H", periods=100, tz=tz)
idx = base.repeat(5)

exp_arr = np.arange(100, dtype=np.intp).repeat(5)
Expand All @@ -317,14 +317,14 @@ def test_factorize_tz(self, tz_naive_fixture):

def test_factorize_dst(self):
# GH 13750
idx = pd.date_range("2016-11-06", freq="H", periods=12, tz="US/Eastern")
idx = date_range("2016-11-06", freq="H", periods=12, tz="US/Eastern")

for obj in [idx, pd.Series(idx)]:
arr, res = obj.factorize()
tm.assert_numpy_array_equal(arr, np.arange(12, dtype=np.intp))
tm.assert_index_equal(res, idx)

idx = pd.date_range("2016-06-13", freq="H", periods=12, tz="US/Eastern")
idx = date_range("2016-06-13", freq="H", periods=12, tz="US/Eastern")

for obj in [idx, pd.Series(idx)]:
arr, res = obj.factorize()
Expand All @@ -350,7 +350,7 @@ def test_unique(self, arr, expected):

def test_asarray_tz_naive(self):
# This shouldn't produce a warning.
idx = pd.date_range("2000", periods=2)
idx = date_range("2000", periods=2)
# M8[ns] by default
result = np.asarray(idx)

Expand All @@ -365,7 +365,7 @@ def test_asarray_tz_naive(self):

def test_asarray_tz_aware(self):
tz = "US/Central"
idx = pd.date_range("2000", periods=2, tz=tz)
idx = date_range("2000", periods=2, tz=tz)
expected = np.array(["2000-01-01T06", "2000-01-02T06"], dtype="M8[ns]")
result = np.asarray(idx, dtype="datetime64[ns]")

Expand Down Expand Up @@ -393,7 +393,7 @@ def test_to_frame_datetime_tz(self):

def test_split_non_utc(self):
# GH 14042
indices = pd.date_range("2016-01-01 00:00:00+0200", freq="S", periods=10)
indices = date_range("2016-01-01 00:00:00+0200", freq="S", periods=10)
result = np.split(indices, indices_or_sections=[])[0]
expected = indices._with_freq(None)
tm.assert_index_equal(result, expected)
Loading