_setitem_with_indexer changes type from datetime to object #26041
Labels
Bug
Duplicate Report
Duplicate issue or pull request
Indexing
Related to indexing on series/frames, not to indexes themselves
Timezones
Timezone data dtype
Uh oh!
There was an error while loading. Please reload this page.
Code Sample, a copy-pastable example if possible
Problem description
Hello all!
I am facing a particularly weird issue, which I have pinpointed to be caused by the _setitem_with_indexer method
From the code above, you can see that when
loc
is used insideperform_operations_that_change_dtype
to retrieve a column and change its timezone, the resulting series is of dtypeobject
instead ofdatetime
. This behavior is not present when using[]
as inperform_operations_that_do_not_change_dtype
, and is only present for DataFrames with single rows. I know that the two approaches are different, but if bothloc
and[]
return the same series, why is the resulting assignment different? From what I can see something happens inside the_setitem_with_indexer
method that changes the type.One thing that might be the issue is the
_try_coerce_args
method insideObjectBlock
: link to line. Why isother
's type changed to object when it is a DatetimeArray?The only similar issue I managed to find is this StackOverflow question that has 0 answers.
Thank you for looking at this issue and for creating and maintaining this amazing library! Hope my findings would be enough to guide someone to help me resolve this; I've been hammering at it the whole day.
Expected Output
The dtype of datetime is not changed to object.
Output of
pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 3.7.2.final.0
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 79 Stepping 1, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None
pandas: 0.24.2
pytest: 4.3.0
pip: 19.0.3
setuptools: 40.8.0
Cython: None
numpy: 1.16.0
scipy: None
pyarrow: None
xarray: None
IPython: 7.2.0
sphinx: None
patsy: None
dateutil: 2.8.0
pytz: 2018.9
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 3.0.3
openpyxl: None
xlrd: 1.2.0
xlwt: None
xlsxwriter: None
lxml.etree: None
bs4: None
html5lib: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
gcsfs: None
The text was updated successfully, but these errors were encountered: