-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
column type changes when assigning with loc and values #26779
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi @blinkseb It seems that changing one of those lines to the following makes it work: df.loc[df['A'].isna(), ['A', 'B']] = df2.values[0] What you are doing with
Sorry, I cannot provide an in-depth explanation into why this is the case as I fully do not understand how pandas works under the hood (yet). However, I don't think this is a bug. Tested using pandas v0.24.2 |
Thanks a lot for the feedback! In this particular case yes, there's a single row in Thanks! |
Looks like a casting bug. I would recommend looking in Block.setitem if you want to debug further. I'm not sure what the expected behavior is here for the output |
Are you replacing missing values in your real example? In that case
df.combine_first(other) may work.
…On Tue, Jun 11, 2019 at 10:04 AM Sébastien Brochet ***@***.***> wrote:
Thanks a lot for the feedback! In this particular case yes, there's a
single row in df2, but in my real usecase, I have more. I'm basically
trying to replace values of N columns with values from another dataframe.
If there's another solution not involving using values, I'd be happy to
use it 😄
Thanks!
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#26779?email_source=notifications&email_token=AAKAOIVZCRQZ2QFOYRTNNWDPZ65IDA5CNFSM4HW4BJIKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODXNN7BY#issuecomment-500883335>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAKAOIVKNSI2CLDHS6NVQ2TPZ65IDANCNFSM4HW4BJIA>
.
|
This returns
now. Seems to be fixed. |
take |
@phofl I'd like to work on adding a test for this. Is |
This should go somewhere into frame/indexing |
Code Sample, a copy-pastable example if possible
Problem description
Hello,
Assigning new values to rows using
.loc
and.values
change the type of the column (look how columnB
, which was adatetime64
, is now a mix of integer and datetime)Note: the same exact code produces the expected output when using pandas 0.22.0, 0.23.4 but broked in pandas 0.24.0 ; also, if I remove the
A
column, the output is correct (no unwanted datetime to integer conversion)Thanks for your help!
Expected Output
Output of
pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 3.6.8.final.0
python-bits: 64
OS: Linux
OS-release: 5.1.7-300.fc30.x86_64
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_GB.UTF-8
LOCALE: en_GB.UTF-8
pandas: 0.24.2
pytest: None
pip: 19.1.1
setuptools: 41.0.1
Cython: None
numpy: 1.16.4
scipy: None
pyarrow: None
xarray: None
IPython: 7.5.0
sphinx: None
patsy: None
dateutil: 2.8.0
pytz: 2019.1
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: None
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml.etree: None
bs4: None
html5lib: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: None
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
gcsfs: None
The text was updated successfully, but these errors were encountered: