Skip to content

Commit f57718e

Browse files
author
yopark
committed
added test case for iloc function if it returns the same output for both numpy and pandas arrays to fix the issue pandas-dev#40933
1 parent 84d9c5e commit f57718e

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

pandas/tests/indexing/multiindex/test_iloc.py

+19
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import numpy as np
22
import pytest
33

4+
import pandas as pd
45
from pandas import (
56
DataFrame,
67
MultiIndex,
@@ -73,6 +74,24 @@ def test_iloc_getitem_multiple_items():
7374
tm.assert_frame_equal(result, expected)
7475

7576

77+
def test_iloc_np_and_pd():
78+
# test if iloc returns the same output for numpy array input and integer array input
79+
df = DataFrame(
80+
data={
81+
"col1": [1, 2, 3, 4],
82+
"col2": [3, 4, 5, 6],
83+
"col3": [6, 7, 8, 9],
84+
}
85+
)
86+
df_np = df
87+
df_pd = df
88+
np_arr = np.array([1, 2, 3])
89+
pd_arr = pd.array([1, 2, 3])
90+
df_np.iloc[[1, 2, 3]] = np_arr
91+
df_pd.iloc[[1, 2, 3]] = pd_arr
92+
tm.assert_frame_equal(df_np, df_pd)
93+
94+
7695
def test_iloc_getitem_labels():
7796
# this is basically regular indexing
7897
arr = np.random.randn(4, 3)

pip

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit e6a65fc5852b0237bb588b00e51ea9384b8f23e4

0 commit comments

Comments
 (0)