Skip to content

.truncate() fails on PeriodIndexes with duplicate values #17717

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

Closed
tui-rob opened this issue Sep 29, 2017 · 1 comment · Fixed by #17755
Closed

.truncate() fails on PeriodIndexes with duplicate values #17717

tui-rob opened this issue Sep 29, 2017 · 1 comment · Fixed by #17755
Labels
Bug Period Period data type
Milestone

Comments

@tui-rob
Copy link
Contributor

tui-rob commented Sep 29, 2017

Truncating a series with a PeriodIndex with unique entries works fine:

In [4]: pdi = pd.PeriodIndex([pd.Period('2017-09-01'),
   ...:                       pd.Period('2017-09-02'),
   ...:                       pd.Period('2017-09-03')])
   ...: ser = pd.Series([1,2,3], index=pdi)
   ...: ser
Out[4]:
2017-09-01    1
2017-09-02    2
2017-09-03    3
Freq: D, dtype: int64

In [5]: ser.truncate(after='2017-09-02')
Out[5]:
2017-09-01    1
2017-09-02    2
Freq: D, dtype: int64

But truncating a series with a PeriodIndex with non-unique entries does not

In [6]: pdi2 = pd.PeriodIndex([pd.Period('2017-09-02'),
   ...:                        pd.Period('2017-09-02'),
   ...:                        pd.Period('2017-09-03')])
   ...: ser2 = pd.Series([1,2,3], index=pdi2)
   ...: ser2
   ...:
Out[6]:
2017-09-02    1
2017-09-02    2
2017-09-03    3
Freq: D, dtype: int64

In [7]: ser2.truncate(after='2017-09-02')

This fails with a TypeError: Cannot compare type 'Period' with type 'int'.

Expected Output

2017-09-02    1
2017-09-02    2
Freq: D, dtype: int64

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.6.1.final.0
python-bits: 32
OS: Windows
OS-release: 7
machine: x86
processor: x86 Family 6 Model 42 Stepping 7, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None

pandas: 0.20.1
pytest: 3.0.7
pip: 9.0.1
setuptools: 27.2.0
Cython: 0.25.2
numpy: 1.12.1
scipy: 0.19.0
xarray: None
IPython: 5.3.0
sphinx: 1.5.6
patsy: 0.4.1
dateutil: 2.6.0
pytz: 2017.2
blosc: None
bottleneck: 1.2.1
tables: 3.2.2
numexpr: 2.6.2
feather: 0.3.1
matplotlib: 2.0.2
openpyxl: 2.4.7
xlrd: 1.0.0
xlwt: 1.2.0
xlsxwriter: 0.9.6
lxml: 3.7.3
bs4: 4.6.0
html5lib: 0.999
sqlalchemy: 1.1.9
pymysql: None
psycopg2: None
jinja2: 2.9.6
s3fs: None
pandas_gbq: None
pandas_datareader: None

@sinhrks sinhrks added Period Period data type Bug labels Sep 29, 2017
@sinhrks
Copy link
Member

sinhrks commented Sep 29, 2017

Looks to be caused by a shortath of _get_loc_duplicates. Non-monotonic duplicates looks work.

pdi3 = pd.PeriodIndex([pd.Period('2017-09-03'),
                       pd.Period('2017-09-02'),
                       pd.Period('2017-09-03')])
ser3 = pd.Series([1,2,3], index=pdi2)
ser3.truncate(after='2017-09-02')
# 2017-09-03    1
# 2017-09-02    2
# Freq: D, dtype: int64

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Period Period data type
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants