Skip to content

BUG: NotImplementedError: Prefix not defined when slicing offset with loc #46671

Closed
@WillianFuks

Description

@WillianFuks

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import numpy as np
import pandas as pd


d = pd.DataFrame(np.random.rand(10, 1))
d.set_index(pd.date_range('01-01-2022', periods=10), inplace=True)
d = d.asfreq(pd.DateOffset(days=1))
d.loc['2022-01-01': '2022-01-03']

Issue Description

As it seems, starting from version 1.4 onward, if the date index is of type offset then when trying to run loc operations raises NotImplementedError: Prefix not defined.

Searching on the web if people had a similar issue but couldn't find much, closest thing seems to be issue #26921.

Expected Behavior

Slicing the date index on specified date points in loc.

Installed Versions

INSTALLED VERSIONS

commit : bb1f651
python : 3.9.5.final.0
python-bits : 64
OS : Linux
OS-release : 5.13.0-39-generic
Version : #44~20.04.1-Ubuntu SMP Thu Mar 24 16:43:35 UTC 2022
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.4.0
numpy : 1.22.3
pytz : 2022.1
dateutil : 2.8.2
pip : 20.0.2
setuptools : 44.0.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 : 3.1.1
IPython : 8.2.0
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.5.1
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugDatetimeDatetime data dtypeIndexingRelated to indexing on series/frames, not to indexes themselvesRegressionFunctionality that used to work in a prior pandas version

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions