Apologies, I cannot use the BUG template as pip install -U pandas
does not go beyond version 1.1.5 on my system, presumably due to a version of Python you no longer support.
Reproducible Example:
import pandas
from io import StringIO
testdata = StringIO("""r_id,text,label
s1,a,n
s2,b,p
s3,c,n
s4,d,p
s5,e,n
""")
df = pandas.read_csv(testdata)
assert len(df) == 5
print(len(df.loc[:4]))
Issue Description: The slice has 5, not 4, items and includes the item s5
.
Expected Behaviour: The slice contains the first 4 items only.
Installed versions:
INSTALLED VERSIONS
------------------
commit : b5958ee1999e9aead1938c0bba2b674378807b3d
python : 3.6.15.final.0
python-bits : 64
OS : Linux
OS-release : 5.3.18-150300.59.98-default
Version : #1 SMP Thu Oct 13 08:52:00 UTC 2022 (dfcde7e)
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_GB.UTF-8
LOCALE : en_GB.UTF-8
pandas : 1.1.5
numpy : 1.19.5
pytz : 2022.6
dateutil : 2.8.2
pip : 21.3.1
setuptools : 59.6.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pyxlsb : None
s3fs : None
scipy : 1.5.4
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None
Comment From: MarcoGorelli
Thanks for your report - this is expected, see https://pandas.pydata.org/docs/user_guide/advanced.html#advanced-endpoints-are-inclusive
closing then