Skip to content

Commit 6641e2b

Browse files
committed
Rename datetime_frame to more descriptive name
1 parent 82eec79 commit 6641e2b

18 files changed

+238
-224
lines changed

pandas/conftest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def axis_series(request):
112112

113113

114114
@pytest.fixture
115-
def datetime_frame():
115+
def float_frame_dt_index():
116116
"""
117117
Fixture for DataFrame of floats with DatetimeIndex
118118

pandas/tests/frame/indexing/test_indexing.py

+19-15
Original file line numberDiff line numberDiff line change
@@ -256,44 +256,48 @@ def inc(x):
256256
tm.assert_frame_equal(df, expected)
257257

258258
def test_getitem_boolean(
259-
self, float_string_frame, mixed_float_frame, mixed_int_frame, datetime_frame
259+
self,
260+
float_string_frame,
261+
mixed_float_frame,
262+
mixed_int_frame,
263+
float_frame_dt_index,
260264
):
261265
# boolean indexing
262-
d = datetime_frame.index[10]
263-
indexer = datetime_frame.index > d
266+
d = float_frame_dt_index.index[10]
267+
indexer = float_frame_dt_index.index > d
264268
indexer_obj = indexer.astype(object)
265269

266-
subindex = datetime_frame.index[indexer]
267-
subframe = datetime_frame[indexer]
270+
subindex = float_frame_dt_index.index[indexer]
271+
subframe = float_frame_dt_index[indexer]
268272

269273
tm.assert_index_equal(subindex, subframe.index)
270274
with pytest.raises(ValueError, match="Item wrong length"):
271-
datetime_frame[indexer[:-1]]
275+
float_frame_dt_index[indexer[:-1]]
272276

273-
subframe_obj = datetime_frame[indexer_obj]
277+
subframe_obj = float_frame_dt_index[indexer_obj]
274278
tm.assert_frame_equal(subframe_obj, subframe)
275279

276280
with pytest.raises(ValueError, match="Boolean array expected"):
277-
datetime_frame[datetime_frame]
281+
float_frame_dt_index[float_frame_dt_index]
278282

279283
# test that Series work
280-
indexer_obj = Series(indexer_obj, datetime_frame.index)
284+
indexer_obj = Series(indexer_obj, float_frame_dt_index.index)
281285

282-
subframe_obj = datetime_frame[indexer_obj]
286+
subframe_obj = float_frame_dt_index[indexer_obj]
283287
tm.assert_frame_equal(subframe_obj, subframe)
284288

285289
# test that Series indexers reindex
286290
# we are producing a warning that since the passed boolean
287291
# key is not the same as the given index, we will reindex
288292
# not sure this is really necessary
289293
with tm.assert_produces_warning(UserWarning, check_stacklevel=False):
290-
indexer_obj = indexer_obj.reindex(datetime_frame.index[::-1])
291-
subframe_obj = datetime_frame[indexer_obj]
294+
indexer_obj = indexer_obj.reindex(float_frame_dt_index.index[::-1])
295+
subframe_obj = float_frame_dt_index[indexer_obj]
292296
tm.assert_frame_equal(subframe_obj, subframe)
293297

294298
# test df[df > 0]
295299
for df in [
296-
datetime_frame,
300+
float_frame_dt_index,
297301
float_string_frame,
298302
mixed_float_frame,
299303
mixed_int_frame,
@@ -320,10 +324,10 @@ def test_getitem_boolean(
320324
if bif[c].dtype != bifw[c].dtype:
321325
assert bif[c].dtype == df[c].dtype
322326

323-
def test_getitem_boolean_casting(self, datetime_frame):
327+
def test_getitem_boolean_casting(self, float_frame_dt_index):
324328

325329
# don't upcast if we don't need to
326-
df = datetime_frame.copy()
330+
df = float_frame_dt_index.copy()
327331
df["E"] = 1
328332
df["E"] = df["E"].astype("int32")
329333
df["E1"] = df["E"].copy()

pandas/tests/frame/indexing/test_xs.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212

1313
class TestXS:
14-
def test_xs(self, float_frame, datetime_frame):
14+
def test_xs(self, float_frame, float_frame_dt_index):
1515
idx = float_frame.index[5]
1616
xs = float_frame.xs(idx)
1717
for item, value in xs.items():
@@ -31,7 +31,7 @@ def test_xs(self, float_frame, datetime_frame):
3131
with pytest.raises(
3232
KeyError, match=re.escape("Timestamp('1999-12-31 00:00:00', freq='B')")
3333
):
34-
datetime_frame.xs(datetime_frame.index[0] - BDay())
34+
float_frame_dt_index.xs(float_frame_dt_index.index[0] - BDay())
3535

3636
# xs get column
3737
series = float_frame.xs("A", axis=1)

pandas/tests/frame/methods/test_cov_corr.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,11 @@ def test_corr_int(self):
155155

156156

157157
class TestDataFrameCorrWith:
158-
def test_corrwith(self, datetime_frame):
159-
a = datetime_frame
158+
def test_corrwith(self, float_frame_dt_index):
159+
a = float_frame_dt_index
160160
noise = Series(np.random.randn(len(a)), index=a.index)
161161

162-
b = datetime_frame.add(noise, axis=0)
162+
b = float_frame_dt_index.add(noise, axis=0)
163163

164164
# make sure order does not matter
165165
b = b.reindex(columns=b.columns[::-1], index=b.index[::-1][10:])
@@ -203,9 +203,9 @@ def test_corrwith_with_objects(self):
203203
expected = df1.loc[:, cols].corrwith(df2.loc[:, cols], axis=1)
204204
tm.assert_series_equal(result, expected)
205205

206-
def test_corrwith_series(self, datetime_frame):
207-
result = datetime_frame.corrwith(datetime_frame["A"])
208-
expected = datetime_frame.apply(datetime_frame["A"].corr)
206+
def test_corrwith_series(self, float_frame_dt_index):
207+
result = float_frame_dt_index.corrwith(float_frame_dt_index["A"])
208+
expected = float_frame_dt_index.apply(float_frame_dt_index["A"].corr)
209209

210210
tm.assert_series_equal(result, expected)
211211

pandas/tests/frame/methods/test_diff.py

+11-10
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77

88

99
class TestDataFrameDiff:
10-
def test_diff(self, datetime_frame):
11-
the_diff = datetime_frame.diff(1)
10+
def test_diff(self, float_frame_dt_index):
11+
the_diff = float_frame_dt_index.diff(1)
1212

1313
tm.assert_series_equal(
14-
the_diff["A"], datetime_frame["A"] - datetime_frame["A"].shift(1)
14+
the_diff["A"],
15+
float_frame_dt_index["A"] - float_frame_dt_index["A"].shift(1),
1516
)
1617

1718
# int dtype
@@ -23,7 +24,7 @@ def test_diff(self, datetime_frame):
2324
assert rs.s[1] == 1
2425

2526
# mixed numeric
26-
tf = datetime_frame.astype("float32")
27+
tf = float_frame_dt_index.astype("float32")
2728
the_diff = tf.diff(1)
2829
tm.assert_series_equal(the_diff["A"], tf["A"] - tf["A"].shift(1))
2930

@@ -99,14 +100,14 @@ def test_diff_mixed_dtype(self):
99100
result = df.diff()
100101
assert result[0].dtype == np.float64
101102

102-
def test_diff_neg_n(self, datetime_frame):
103-
rs = datetime_frame.diff(-1)
104-
xp = datetime_frame - datetime_frame.shift(-1)
103+
def test_diff_neg_n(self, float_frame_dt_index):
104+
rs = float_frame_dt_index.diff(-1)
105+
xp = float_frame_dt_index - float_frame_dt_index.shift(-1)
105106
tm.assert_frame_equal(rs, xp)
106107

107-
def test_diff_float_n(self, datetime_frame):
108-
rs = datetime_frame.diff(1.0)
109-
xp = datetime_frame.diff(1)
108+
def test_diff_float_n(self, float_frame_dt_index):
109+
rs = float_frame_dt_index.diff(1.0)
110+
xp = float_frame_dt_index.diff(1)
110111
tm.assert_frame_equal(rs, xp)
111112

112113
def test_diff_axis(self):

pandas/tests/frame/methods/test_pct_change.py

+17-13
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,22 @@ def test_pct_change_numeric(self):
2121

2222
tm.assert_frame_equal(result, expected)
2323

24-
def test_pct_change(self, datetime_frame):
25-
rs = datetime_frame.pct_change(fill_method=None)
26-
tm.assert_frame_equal(rs, datetime_frame / datetime_frame.shift(1) - 1)
24+
def test_pct_change(self, float_frame_dt_index):
25+
rs = float_frame_dt_index.pct_change(fill_method=None)
26+
tm.assert_frame_equal(
27+
rs, float_frame_dt_index / float_frame_dt_index.shift(1) - 1
28+
)
2729

28-
rs = datetime_frame.pct_change(2)
29-
filled = datetime_frame.fillna(method="pad")
30+
rs = float_frame_dt_index.pct_change(2)
31+
filled = float_frame_dt_index.fillna(method="pad")
3032
tm.assert_frame_equal(rs, filled / filled.shift(2) - 1)
3133

32-
rs = datetime_frame.pct_change(fill_method="bfill", limit=1)
33-
filled = datetime_frame.fillna(method="bfill", limit=1)
34+
rs = float_frame_dt_index.pct_change(fill_method="bfill", limit=1)
35+
filled = float_frame_dt_index.fillna(method="bfill", limit=1)
3436
tm.assert_frame_equal(rs, filled / filled.shift(1) - 1)
3537

36-
rs = datetime_frame.pct_change(freq="5D")
37-
filled = datetime_frame.fillna(method="pad")
38+
rs = float_frame_dt_index.pct_change(freq="5D")
39+
filled = float_frame_dt_index.fillna(method="pad")
3840
tm.assert_frame_equal(
3941
rs, (filled / filled.shift(freq="5D") - 1).reindex_like(filled)
4042
)
@@ -61,18 +63,20 @@ def test_pct_change_shift_over_nas(self):
6163
],
6264
)
6365
def test_pct_change_periods_freq(
64-
self, datetime_frame, freq, periods, fill_method, limit
66+
self, float_frame_dt_index, freq, periods, fill_method, limit
6567
):
6668
# GH#7292
67-
rs_freq = datetime_frame.pct_change(
69+
rs_freq = float_frame_dt_index.pct_change(
6870
freq=freq, fill_method=fill_method, limit=limit
6971
)
70-
rs_periods = datetime_frame.pct_change(
72+
rs_periods = float_frame_dt_index.pct_change(
7173
periods, fill_method=fill_method, limit=limit
7274
)
7375
tm.assert_frame_equal(rs_freq, rs_periods)
7476

75-
empty_ts = DataFrame(index=datetime_frame.index, columns=datetime_frame.columns)
77+
empty_ts = DataFrame(
78+
index=float_frame_dt_index.index, columns=float_frame_dt_index.columns
79+
)
7680
rs_freq = empty_ts.pct_change(freq=freq, fill_method=fill_method, limit=limit)
7781
rs_periods = empty_ts.pct_change(periods, fill_method=fill_method, limit=limit)
7882
tm.assert_frame_equal(rs_freq, rs_periods)

pandas/tests/frame/methods/test_quantile.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ def test_quantile_sparse(self):
1717
expected = pd.Series([1.5, 3.5], name=0.5)
1818
tm.assert_series_equal(result, expected)
1919

20-
def test_quantile(self, datetime_frame):
20+
def test_quantile(self, float_frame_dt_index):
2121
from numpy import percentile
2222

23-
df = datetime_frame
23+
df = float_frame_dt_index
2424
q = df.quantile(0.1, axis=0)
2525
assert q["A"] == percentile(df["A"], 10)
2626
tm.assert_index_equal(q.index, df.columns)
@@ -163,11 +163,11 @@ def test_quantile_interpolation(self):
163163
)
164164
tm.assert_frame_equal(result, expected)
165165

166-
def test_quantile_interpolation_datetime(self, datetime_frame):
166+
def test_quantile_interpolation_datetime(self, float_frame_dt_index):
167167
# see gh-10174
168168

169169
# interpolation = linear (default case)
170-
df = datetime_frame
170+
df = float_frame_dt_index
171171
q = df.quantile(0.1, axis=0, interpolation="linear")
172172
assert q["A"] == np.percentile(df["A"], 10)
173173

@@ -251,11 +251,11 @@ def test_quantile_datetime(self):
251251
# result = df[['a', 'c']].quantile(.5)
252252
# result = df[['a', 'c']].quantile([.5])
253253

254-
def test_quantile_invalid(self, datetime_frame):
254+
def test_quantile_invalid(self, float_frame_dt_index):
255255
msg = "percentiles should all be in the interval \\[0, 1\\]"
256256
for invalid in [-1, 2, [0.5, -1], [0.5, 2]]:
257257
with pytest.raises(ValueError, match=msg):
258-
datetime_frame.quantile(invalid)
258+
float_frame_dt_index.quantile(invalid)
259259

260260
def test_quantile_box(self):
261261
df = DataFrame(

pandas/tests/frame/methods/test_replace.py

+29-29
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ def mix_abc() -> Dict[str, List[Union[float, str]]]:
2222

2323

2424
class TestDataFrameReplace:
25-
def test_replace_inplace(self, datetime_frame, float_string_frame):
26-
datetime_frame["A"][:5] = np.nan
27-
datetime_frame["A"][-5:] = np.nan
25+
def test_replace_inplace(self, float_frame_dt_index, float_string_frame):
26+
float_frame_dt_index["A"][:5] = np.nan
27+
float_frame_dt_index["A"][-5:] = np.nan
2828

29-
tsframe = datetime_frame.copy()
29+
tsframe = float_frame_dt_index.copy()
3030
tsframe.replace(np.nan, 0, inplace=True)
31-
tm.assert_frame_equal(tsframe, datetime_frame.fillna(0))
31+
tm.assert_frame_equal(tsframe, float_frame_dt_index.fillna(0))
3232

3333
# mixed type
3434
mf = float_string_frame
@@ -39,9 +39,9 @@ def test_replace_inplace(self, datetime_frame, float_string_frame):
3939
expected = float_string_frame.fillna(value=0)
4040
tm.assert_frame_equal(result, expected)
4141

42-
tsframe = datetime_frame.copy()
42+
tsframe = float_frame_dt_index.copy()
4343
tsframe.replace([np.nan], [0], inplace=True)
44-
tm.assert_frame_equal(tsframe, datetime_frame.fillna(0))
44+
tm.assert_frame_equal(tsframe, float_frame_dt_index.fillna(0))
4545

4646
def test_regex_replace_scalar(self, mix_ab):
4747
obj = {"a": list("ab.."), "b": list("efgh")}
@@ -582,17 +582,17 @@ def test_replace_regex_metachar(self, metachar):
582582
expected = DataFrame({"a": ["paren", "else"]})
583583
tm.assert_frame_equal(result, expected)
584584

585-
def test_replace(self, datetime_frame):
586-
datetime_frame["A"][:5] = np.nan
587-
datetime_frame["A"][-5:] = np.nan
585+
def test_replace(self, float_frame_dt_index):
586+
float_frame_dt_index["A"][:5] = np.nan
587+
float_frame_dt_index["A"][-5:] = np.nan
588588

589-
zero_filled = datetime_frame.replace(np.nan, -1e8)
590-
tm.assert_frame_equal(zero_filled, datetime_frame.fillna(-1e8))
591-
tm.assert_frame_equal(zero_filled.replace(-1e8, np.nan), datetime_frame)
589+
zero_filled = float_frame_dt_index.replace(np.nan, -1e8)
590+
tm.assert_frame_equal(zero_filled, float_frame_dt_index.fillna(-1e8))
591+
tm.assert_frame_equal(zero_filled.replace(-1e8, np.nan), float_frame_dt_index)
592592

593-
datetime_frame["A"][:5] = np.nan
594-
datetime_frame["A"][-5:] = np.nan
595-
datetime_frame["B"][:5] = -1e8
593+
float_frame_dt_index["A"][:5] = np.nan
594+
float_frame_dt_index["A"][-5:] = np.nan
595+
float_frame_dt_index["B"][:5] = -1e8
596596

597597
# empty
598598
df = DataFrame(index=["a", "b"])
@@ -792,30 +792,30 @@ def test_replace_simple_nested_dict_with_nonexistent_value(self):
792792
result = df.replace({"col": {-1: "-", 1: "a", 4: "b"}})
793793
tm.assert_frame_equal(expected, result)
794794

795-
def test_replace_value_is_none(self, datetime_frame):
796-
orig_value = datetime_frame.iloc[0, 0]
797-
orig2 = datetime_frame.iloc[1, 0]
795+
def test_replace_value_is_none(self, float_frame_dt_index):
796+
orig_value = float_frame_dt_index.iloc[0, 0]
797+
orig2 = float_frame_dt_index.iloc[1, 0]
798798

799-
datetime_frame.iloc[0, 0] = np.nan
800-
datetime_frame.iloc[1, 0] = 1
799+
float_frame_dt_index.iloc[0, 0] = np.nan
800+
float_frame_dt_index.iloc[1, 0] = 1
801801

802-
result = datetime_frame.replace(to_replace={np.nan: 0})
803-
expected = datetime_frame.T.replace(to_replace={np.nan: 0}).T
802+
result = float_frame_dt_index.replace(to_replace={np.nan: 0})
803+
expected = float_frame_dt_index.T.replace(to_replace={np.nan: 0}).T
804804
tm.assert_frame_equal(result, expected)
805805

806-
result = datetime_frame.replace(to_replace={np.nan: 0, 1: -1e8})
807-
tsframe = datetime_frame.copy()
806+
result = float_frame_dt_index.replace(to_replace={np.nan: 0, 1: -1e8})
807+
tsframe = float_frame_dt_index.copy()
808808
tsframe.iloc[0, 0] = 0
809809
tsframe.iloc[1, 0] = -1e8
810810
expected = tsframe
811811
tm.assert_frame_equal(expected, result)
812-
datetime_frame.iloc[0, 0] = orig_value
813-
datetime_frame.iloc[1, 0] = orig2
812+
float_frame_dt_index.iloc[0, 0] = orig_value
813+
float_frame_dt_index.iloc[1, 0] = orig2
814814

815-
def test_replace_for_new_dtypes(self, datetime_frame):
815+
def test_replace_for_new_dtypes(self, float_frame_dt_index):
816816

817817
# dtypes
818-
tsframe = datetime_frame.copy().astype(np.float32)
818+
tsframe = float_frame_dt_index.copy().astype(np.float32)
819819
tsframe["A"][:5] = np.nan
820820
tsframe["A"][-5:] = np.nan
821821

0 commit comments

Comments
 (0)