You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importpandasaspd# generate two Series randomlyt1=pd.Series([1.2,2.2,3.0,4,8],index=pd.date_range(start='2015-5-14 00:00:00',end='2015-5-14 00:04:00',freq='T'))
t2=pd.Series([6.5,7.2,8.1,9],index=pd.date_range(start='2015-5-15 00:00:00',end='2015-5-15 00:03:00',freq='T'))
# merge t2 ,t1 -> t3t3=pd.concat([t2,t1])
key='2015-5-14 00:00:00'print('type t1 is ',type(t1))
print('type t3 is ',type(t3))
print('(1):',t1[key])
print('(2):',t3[key])
print('(3):',t3[key:key])
Problem description
type t1 is <class 'pandas.core.series.Series'>
type t3 is <class 'pandas.core.series.Series'>
(1): 1.2
(2): 2015-05-14 1.2
dtype: float64
(3): 2015-05-14 1.2
dtype: float64
firstly I concat t1 and t2 and got t3 ,than we can compare t1[key] , t3[key] and t3[key:key]
I think we expect t3[key] just work like t1[key],but t3[key] work same as t3[key:key]
it makes people confused extremely, in fact,I cost hours for that
I agreed that this is pretty inconsistent. Here's a simpler example without the concat step, as overall I think this has to do with whether the index is monotonic:
mroeschke
changed the title
unexpected behavior after pd.concat
Indexing with Series.__getitem__ with DatetimeIndex differs based on monotonicity
Jan 24, 2019
Using @mroeschke's example, it looks like the behavior diverges when we get to DatetimeIndex._partial_date_slice, which starts with a check:
is_monotonic = self.is_monotonic
if (
is_monotonic
and reso in ["day", "hour", "minute", "second"]
and self._resolution >= Resolution.get_reso(reso)
):
# These resolution/monotonicity validations came from GH3931,
# GH3452 and GH2369.
# See also GH14826
raise KeyError
this raises for the monotonic index but not the non-monotonic one.
Code Sample, a copy-pastable example if possible
Problem description
Expected Output
Output of
pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 3.6.6.final.0
python-bits: 64
OS: Darwin
OS-release: 17.5.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None
pandas: 0.23.4
pytest: None
pip: 18.1
setuptools: 36.4.0
Cython: None
numpy: 1.12.1
scipy: 0.19.1
pyarrow: None
xarray: None
IPython: 7.1.1
sphinx: None
patsy: 0.5.1
dateutil: 2.7.5
pytz: 2017.2
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 3.0.1
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
The text was updated successfully, but these errors were encountered: