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
Fix related issue
  • Loading branch information
phofl committed Nov 15, 2020
commit 27ea3e29da04b767912965ed61a37d75e41b098a
5 changes: 5 additions & 0 deletions pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

from pandas._libs.indexing import NDFrameIndexerBase
from pandas._libs.lib import item_from_zerodim

from pandas.core.dtypes.cast import infer_dtype_from_scalar
from pandas.errors import AbstractMethodError, InvalidIndexError
from pandas.util._decorators import doc

Expand Down Expand Up @@ -1552,6 +1554,9 @@ def _setitem_with_indexer(self, indexer, value):
blk = self.obj._mgr.blocks[0]
take_split_path = not blk._can_hold_element(val)
Copy link
Contributor

Choose a reason for hiding this comment

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

this can be the else condtiion

Copy link
Member Author

Choose a reason for hiding this comment

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

No, value can be anything from int, float to numpy array. I think this check is only necessary if we have Series or DataFrame. Maybe with an array?

if not take_split_path:
if is_scalar(value):
dtype = infer_dtype_from_scalar(value)
take_split_path = not is_dtype_equal(dtype, blk.dtype)
if isinstance(value, ABCSeries):
take_split_path = not (is_dtype_equal(value.dtype, blk.dtype))
elif isinstance(value, ABCDataFrame):
Expand Down
12 changes: 12 additions & 0 deletions pandas/tests/frame/indexing/test_setitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,18 @@ def test_setitem_conversion_to_datetime(self):
)
tm.assert_frame_equal(df, expected)

def test_setitem_scalar_dtype_change(self):
# GH#27583
df = DataFrame({"a": [0.0], "b": [0.0]})
df[["a", "b"]] = 0
expected = DataFrame({"a": [0], "b": [0]})
tm.assert_frame_equal(df, expected)

df = DataFrame({"a": [0.0], "b": [0.0]})
df["b"] = 0
expected = DataFrame({"a": [0.0], "b": [0]})
tm.assert_frame_equal(df, expected)


class TestDataFrameSetItemSlicing:
def test_setitem_slice_position(self):
Expand Down