Skip to content

Commit 67b8150

Browse files
committed
Added tests for DataFrame alongside Series
1 parent 258adc4 commit 67b8150

File tree

1 file changed

+43
-18
lines changed

1 file changed

+43
-18
lines changed

pandas/tests/indexing/test_scalar.py

+43-18
Original file line numberDiff line numberDiff line change
@@ -313,38 +313,63 @@ def test_iat_series_with_period_index():
313313
assert expected == result
314314

315315

316-
def test_tuple_indexed_series_at_get():
316+
def test_at_with_tuple_index_get():
317317
# GH 26989
318-
# Series.at works with index of tuples
319-
series = Series([1, 2], index=[(1, 2), (3, 4)])
318+
# DataFrame.at getter works with Index of tuples
319+
df = DataFrame({"a": [1, 2]}, index=[(1, 2), (3, 4)])
320+
assert df.index.nlevels == 1
321+
assert df.at[(1, 2), "a"] == 1
322+
323+
# Series.at getter works with Index of tuples
324+
series = df["a"]
320325
assert series.index.nlevels == 1
321-
assert series.at[1, 2] == 1
326+
assert series.at[(1, 2)] == 1
322327

323328

324-
def test_tuple_indexed_series_at_set():
329+
def test_at_with_tuple_index_set():
325330
# GH 26989
326-
# Series.at works with index of tuples
327-
series = Series([1, 2], index=[(1, 2), (3, 4)])
328-
series.at[1, 2] = 3
331+
# DataFrame.at setter works with Index of tuples
332+
df = DataFrame({"a": [1, 2]}, index=[(1, 2), (3, 4)])
333+
assert df.index.nlevels == 1
334+
df.at[(1, 2), "a"] = 2
335+
assert df.at[(1, 2), "a"] == 2
336+
337+
# Series.at setter works with Index of tuples
338+
series = df["a"]
329339
assert series.index.nlevels == 1
340+
series.at[1, 2] = 3
330341
assert series.at[1, 2] == 3
331342

332343

333-
def test_multiindex_series_at_get():
344+
def test_multiindex_at_get():
334345
# GH 26989
335-
# Series.at works with MultiIndex
336-
series = Series([1, 2], index=[[1, 2], [3, 4]])
346+
# DataFrame.at and DataFrame.loc getter works with MultiIndex
347+
df = DataFrame({"a": [1, 2]}, index=[[1, 2], [3, 4]])
348+
assert df.index.nlevels == 2
349+
assert df.at[(1, 3), "a"] == 1
350+
assert df.loc[(1, 3), "a"] == 1
351+
352+
# Series.at and Series.loc getter works with MultiIndex
353+
series = df["a"]
337354
assert series.index.nlevels == 2
338355
assert series.at[1, 3] == 1
339356
assert series.loc[1, 3] == 1
340357

341358

342-
def test_multiindex_series_at_set():
359+
def test_multiindex_at_set():
343360
# GH 26989
344-
# Series.at works with MultiIndex
345-
series = Series([1, 2], index=[[1, 2], [3, 4]])
361+
# DataFrame.at and DataFrame.loc setter works with MultiIndex
362+
df = DataFrame({"a": [1, 2]}, index=[[1, 2], [3, 4]])
363+
assert df.index.nlevels == 2
364+
df.at[(1, 3), "a"] = 3
365+
assert df.at[(1, 3), "a"] == 3
366+
df.loc[(1, 3), "a"] = 4
367+
assert df.loc[(1, 3), "a"] == 4
368+
369+
# Series.at and Series.loc setter works with MultiIndex
370+
series = df["a"]
346371
assert series.index.nlevels == 2
347-
series.at[1, 3] = 3
348-
assert series.at[1, 3] == 3
349-
series.loc[1, 3] = 4
350-
assert series.loc[1, 3] == 4
372+
series.at[1, 3] = 5
373+
assert series.at[1, 3] == 5
374+
series.loc[1, 3] = 6
375+
assert series.loc[1, 3] == 6

0 commit comments

Comments
 (0)