Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
6450a2c
BUG: Bug in loc did not change dtype when complete columne was assigned
phofl Nov 10, 2020
1599c5c
Fix list comprehension issue
phofl Nov 10, 2020
4d39612
Fix import order
phofl Nov 10, 2020
f9f37cb
Add test
phofl Nov 11, 2020
5cf355b
Merge branch 'master' of https://github.com/pandas-dev/pandas into 20635
phofl Nov 11, 2020
8d203f9
Change dtype for 32 bit
phofl Nov 11, 2020
e35e009
Implement fix and add new test
phofl Nov 11, 2020
4c391da
Merge branch 'master' of https://github.com/pandas-dev/pandas into 20635
phofl Nov 13, 2020
71fbf9f
Add new column
phofl Nov 13, 2020
babcd38
Run black
phofl Nov 13, 2020
caa6046
Parametrize tests
phofl Nov 13, 2020
8b95236
Merge branch 'master' of https://github.com/pandas-dev/pandas into 20635
phofl Nov 13, 2020
3b98ee0
Adress review comments
phofl Nov 14, 2020
f9b8a59
Change whatsnew wording
phofl Nov 14, 2020
4bef38e
Simplify tests
phofl Nov 14, 2020
27ea3e2
Fix related issue
phofl Nov 15, 2020
f94277b
Add issues
phofl Nov 15, 2020
279e812
Merge branch 'master' of https://github.com/pandas-dev/pandas into 20635
phofl Nov 15, 2020
d5f6150
Move import
phofl Nov 15, 2020
706dc6a
Delete line
phofl Nov 15, 2020
66d4b4e
Fix return value
phofl Nov 15, 2020
fa25075
Move and rename tests
phofl Nov 17, 2020
3c06ba6
Fix failing test
phofl Nov 17, 2020
a33659c
Merge branch 'master' of https://github.com/pandas-dev/pandas into 20635
phofl Nov 17, 2020
0f556c4
Fix pre commit
phofl Nov 17, 2020
181e62a
Merge branch 'master' of https://github.com/pandas-dev/pandas into 20635
phofl Nov 17, 2020
b759ac9
Remove import
phofl Nov 17, 2020
a353930
Fix test
phofl Nov 17, 2020
d28e1e1
Add test
phofl Nov 17, 2020
1aa8522
Adress review comments
phofl Nov 20, 2020
1bc0d46
Fix test
phofl Nov 21, 2020
61aab16
Merge branch 'master' of https://github.com/pandas-dev/pandas into 20635
phofl Nov 21, 2020
14fe5a8
Move test
phofl Nov 21, 2020
26b5d6f
Fix test
phofl Nov 21, 2020
913ffea
Merge branch 'master' of https://github.com/pandas-dev/pandas into 20635
phofl Nov 22, 2020
e6e22f3
Fix bug with series to cell
phofl Nov 22, 2020
23f6f3b
Merge branch 'master' of https://github.com/pandas-dev/pandas into 20635
phofl Nov 22, 2020
99b87c9
Merge branch 'master' of https://github.com/pandas-dev/pandas into 20635
phofl Dec 23, 2020
f97a252
Move whatsnew
phofl Dec 23, 2020
700ce6c
Merge branch 'master' of https://github.com/pandas-dev/pandas into 20635
phofl Feb 13, 2021
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
Prev Previous commit
Next Next commit
Move and rename tests
  • Loading branch information
phofl committed Nov 17, 2020
commit fa250752efaa9566c0cf280acedaaeaeae933073
34 changes: 0 additions & 34 deletions pandas/tests/frame/indexing/test_setitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,40 +299,6 @@ def test_iloc_setitem_bool_indexer(self, klass):
expected = DataFrame({"flag": ["x", "y", "z"], "value": [2, 3, 4]})
tm.assert_frame_equal(df, expected)

@pytest.mark.parametrize("dtype", ["int64", "Int64"])
def test_setitem_complete_columns_different_dtypes(self, dtype):
# GH: 20635
df = DataFrame({"A": ["a", "b"], "B": ["1", "2"], "C": ["3", "4"], "D": [1, 2]})
rhs = df[["B", "C"]].astype("int64").astype(dtype)
df.loc[:, ["B", "C"]] = rhs
expected = DataFrame({"A": ["a", "b"], "B": [1, 2], "C": [3, 4], "D": [1, 2]})
expected[["B", "C"]] = expected[["B", "C"]].astype(dtype)
tm.assert_frame_equal(df, expected)

def test_setitem_single_column_as_series_different_dtype(self):
# GH: 20635
df = DataFrame({"A": ["a", "b"], "B": ["1", "2"], "C": ["3", "4"]})
df.loc[:, "C"] = df["C"].astype("int64")
expected = DataFrame({"A": ["a", "b"], "B": ["1", "2"], "C": [3, 4]})
tm.assert_frame_equal(df, expected)

def test_setitem_conversion_to_datetime(self):
# GH: 20511
df = DataFrame(
[["2015-01-01", "2016-01-01"], ["2016-01-01", "2015-01-01"]],
columns=["date0", "date1"],
)
df.iloc[:, [0]] = df.iloc[:, [0]].apply(
lambda x: to_datetime(x, errors="coerce")
)
expected = DataFrame(
{
"date0": [to_datetime("2015-01-01"), to_datetime("2016-01-01")],
"date1": ["2016-01-01", "2015-01-01"],
}
)
tm.assert_frame_equal(df, expected)

def test_setitem_scalar_dtype_change(self):
# GH#27583
df = DataFrame({"a": [0.0], "b": [0.0]})
Expand Down
18 changes: 18 additions & 0 deletions pandas/tests/indexing/test_iloc.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
concat,
date_range,
isna,
to_datetime,
)
import pandas._testing as tm
from pandas.api.types import is_scalar
Expand Down Expand Up @@ -801,6 +802,23 @@ def test_iloc_setitem_empty_frame_raises_with_3d_ndarray(self):
with pytest.raises(ValueError, match=msg):
obj.iloc[nd3] = 0

def test_setitem_conversion_to_datetime(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test_iloc_setitem_...

# GH: 20511
df = DataFrame(
[["2015-01-01", "2016-01-01"], ["2016-01-01", "2015-01-01"]],
columns=["date0", "date1"],
)
df.iloc[:, [0]] = df.iloc[:, [0]].apply(
lambda x: to_datetime(x, errors="coerce")
)
expected = DataFrame(
{
"date0": [to_datetime("2015-01-01"), to_datetime("2016-01-01")],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you use Timestamp instead of to_datetime

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

"date1": ["2016-01-01", "2015-01-01"],
}
)
tm.assert_frame_equal(df, expected)


class TestILocErrors:
# NB: this test should work for _any_ Series we can pass as
Expand Down
25 changes: 25 additions & 0 deletions pandas/tests/indexing/test_loc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1127,6 +1127,23 @@ def test_loc_setitem_listlike_with_timedelta64index(self, indexer, expected):

tm.assert_frame_equal(expected, df)

def test_setitem_null_slice_single_column_series_value_different_dtype(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test_loc_setitem

# GH: 20635
df = DataFrame({"A": ["a", "b"], "B": ["1", "2"], "C": ["3", "4"]})
df.loc[:, "C"] = df["C"].astype("int64")
expected = DataFrame({"A": ["a", "b"], "B": ["1", "2"], "C": [3, 4]})
tm.assert_frame_equal(df, expected)

@pytest.mark.parametrize("dtype", ["int64", "Int64"])
def test_setitem_null_slice_different_dtypes(self, dtype):
# GH: 20635
df = DataFrame({"A": ["a", "b"], "B": ["1", "2"], "C": ["3", "4"], "D": [1, 2]})
rhs = df[["B", "C"]].astype("int64").astype(dtype)
df.loc[:, ["B", "C"]] = rhs
expected = DataFrame({"A": ["a", "b"], "B": [1, 2], "C": [3, 4], "D": [1, 2]})
expected[["B", "C"]] = expected[["B", "C"]].astype(dtype)
tm.assert_frame_equal(df, expected)


class TestLocWithMultiIndex:
@pytest.mark.parametrize(
Expand Down Expand Up @@ -1995,6 +2012,14 @@ def test_loc_setitem_dt64tz_values(self):
result = s2["a"]
assert result == expected

@pytest.mark.parametrize("dtype", ["int64", "Int64"])
def test_setitem_series_null_slice_different_dtypes(self, dtype):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test_loc_setitem_...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx, changed all test names and fixed failing tests.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one still shows as test_setitem instead of test_loc_setitem

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird, was certain to have changed this. Now it shows correctly

# GH: 20635
ser = Series(["3", "4"], name="A")
ser.loc[:] = ser.astype("int64").astype(dtype)
expected = Series([3, 4], name="A", dtype=dtype)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this is doing the opposite of #39163. did we decide to revert part or all of that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since yours is significantly newer I am fine with „closing“ this. Would check if some of the issues are fixed

tm.assert_series_equal(ser, expected)


@pytest.mark.parametrize("value", [1, 1.5])
def test_loc_int_in_object_index(frame_or_series, value):
Expand Down
8 changes: 0 additions & 8 deletions pandas/tests/series/indexing/test_setitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,6 @@ def test_setitem_nan_casts(self):
ser[:5] = np.nan
tm.assert_series_equal(ser, expected)

@pytest.mark.parametrize("dtype", ["int64", "Int64"])
def test_setitem_assigning_different_dtype(self, dtype):
# GH: 20635
ser = Series(["3", "4"], name="A")
ser.loc[:] = ser.astype("int64").astype(dtype)
expected = Series([3, 4], name="A", dtype=dtype)
tm.assert_series_equal(ser, expected)


class TestSetitemWithExpansion:
def test_setitem_empty_series(self):
Expand Down