Skip to content

BUG: inconsistency between PeriodIndex.get_value vs get_loc #31172

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

Merged
merged 6 commits into from
Jan 25, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
update per comments
  • Loading branch information
jbrockmendel committed Jan 25, 2020
commit 512b274c8022ef75e7baf6824d9984f54e3f57e2
43 changes: 22 additions & 21 deletions pandas/core/indexes/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ def get_value(self, series, key):
try:
loc = self._get_string_slice(key)
return series[loc]
except (TypeError, ValueError):
except (TypeError, ValueError, OverflowError):
pass

asdt, reso = parse_time_string(key, self.freq)
Expand Down Expand Up @@ -572,27 +572,28 @@ def get_loc(self, key, method=None, tolerance=None):
loc = self._get_string_slice(key)
return loc
except (TypeError, ValueError):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OverflowError can no longer occur?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ill see if i can cook up a test case that overflows

pass

try:
asdt, reso = parse_time_string(key, self.freq)
except DateParseError:
# A string with invalid format
raise KeyError(f"Cannot interpret '{key}' as period")

try:
asdt, reso = parse_time_string(key, self.freq)
except DateParseError:
# A string with invalid format
raise KeyError(f"Cannot interpret '{key}' as period")

grp = resolution.Resolution.get_freq_group(reso)
freqn = resolution.get_freq_group(self.freq)

# _get_string_slice will handle cases where grp < freqn
assert grp >= freqn

if grp == freqn:
key = Period(asdt, freq=self.freq)
loc = self.get_loc(key, method=method, tolerance=tolerance)
return loc
elif method is None:
raise KeyError(key)
else:
key = asdt
grp = resolution.Resolution.get_freq_group(reso)
freqn = resolution.get_freq_group(self.freq)

# _get_string_slice will handle cases where grp < freqn
assert grp >= freqn

if grp == freqn:
key = Period(asdt, freq=self.freq)
loc = self.get_loc(key, method=method, tolerance=tolerance)
return loc
elif method is None:
raise KeyError(key)
else:
key = asdt

elif is_integer(key):
# Period constructor will cast to string, which we dont want
Expand Down