Skip to content

PeriodIndex with float input inconsistency #13232

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
sinhrks opened this issue May 19, 2016 · 12 comments
Closed

PeriodIndex with float input inconsistency #13232

sinhrks opened this issue May 19, 2016 · 12 comments
Labels
Milestone

Comments

@sinhrks
Copy link
Member

sinhrks commented May 19, 2016

Code Sample, a copy-pastable example if possible

pd.PeriodIndex([1.1], freq='M')
# ValueError: Given date string not likely a datetime.

pd.PeriodIndex(np.array([1.1]), freq='M')
# PeriodIndex(['1970-02'], dtype='int64', freq='M'

Expected Output

Consistently raise or coerce to Period

output of pd.show_versions()

0.18.1

CC: @MaximilianR

@sinhrks sinhrks added Bug API Design Period Period data type labels May 19, 2016
@max-sixty
Copy link
Contributor

ref #13079, which should fix

@max-sixty
Copy link
Contributor

@sinhrks @jreback closed by #13079

@jreback jreback added this to the 0.18.2 milestone May 21, 2016
@jreback jreback closed this as completed May 21, 2016
@jreback
Copy link
Contributor

jreback commented May 21, 2016

@MaximilianR if you think we need to add a note (and/or include these issues) in the whatsnew, pls do a PR. I don't care about the issues per-se being referenced by GH does that. But if you are a user and want to know (and the existing notes don't cover), then pls add.

@max-sixty
Copy link
Contributor

@jreback this seems like pretty deep in the internals - shall I still add one?

@jreback
Copy link
Contributor

jreback commented May 21, 2016

nah I looked again, its fine. thxs!

Periods really coming along!

@sinhrks
Copy link
Member Author

sinhrks commented May 21, 2016

@MaximilianR #13079 only checks _shallow_copy with normal float input right?

on current master (d2b5819):

pd.PeriodIndex(np.array([1.1, np.nan, np.inf]), freq='M')
# PeriodIndex(['1970-02', 'NaT', 'NaT'], dtype='int64', freq='M')

pd.PeriodIndex([1.1, np.nan, np.inf], freq='M')
# ValueError: Value must be Period, string, integer, or datetime

reopens.

@sinhrks sinhrks reopened this May 21, 2016
@jreback
Copy link
Contributor

jreback commented May 21, 2016

In [2]: pd.PeriodIndex(np.array([1.1]), freq='M')
Out[2]: PeriodIndex(['1970-02'], dtype='int64', freq='M')

actually the original [2] should be an error as well (and ValueError is correct here)

@max-sixty
Copy link
Contributor

Apologies. Will PR

@max-sixty
Copy link
Contributor

Why a ValueError rather than TypeError?

@jreback
Copy link
Contributor

jreback commented May 21, 2016

oh these could be TypeError, but we mostly raise ValueError now

@max-sixty
Copy link
Contributor

max-sixty commented May 21, 2016

Looking through this, I think this is a pretty weird code path - only gets hit with ints that can represent Periods, which I think are just years (e.g. '2000'). Not ints representing the underlying values... https://github.com/pydata/pandas/blob/master/pandas/tseries/period.py#L229

@jreback
Copy link
Contributor

jreback commented May 21, 2016

hmm, yeah that does seem weird; I prob would just try to astype('i8') if it fails take that path.

@jorisvandenbossche jorisvandenbossche modified the milestones: Next Major Release, 0.19.0 Aug 21, 2016
@jreback jreback modified the milestones: 0.20.0, Next Major Release Jan 2, 2017
@jreback jreback closed this as completed in ca6d88b Mar 4, 2017
AnkurDedania pushed a commit to AnkurDedania/pandas that referenced this issue Mar 21, 2017
closes pandas-dev#13232

Material clean up of PeriodIndex constructor, which was doing a few
weird things (pandas-dev#13232 (comment)
nt-220788816), and generally getting messy.

Author: Maximilian Roos <[email protected]>

Closes pandas-dev#13277 from MaximilianR/period-float and squashes the following commits:

5cae7aa [Maximilian Roos] @jreback changes
75ff54d [Maximilian Roos] _new_PeriodIndex for unpickling
240172f [Maximilian Roos] coerce freq object earlier for perf
ba5133b [Maximilian Roos] documentation
b0fc0a7 [Maximilian Roos] final changes
fa0fa9d [Maximilian Roos] clean up PeriodIndex constructor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants