Skip to content

CLN: simplify maybe_normalize_endpoints #49099

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 1 commit into from
Oct 14, 2022
Merged
Changes from all commits
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
18 changes: 5 additions & 13 deletions pandas/core/arrays/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ def _generate_range( # type: ignore[override]
raise ValueError("Neither `start` nor `end` can be NaT")

left_inclusive, right_inclusive = validate_inclusive(inclusive)
start, end, _normalized = _maybe_normalize_endpoints(start, end, normalize)
start, end = _maybe_normalize_endpoints(start, end, normalize)
tz = _infer_tz_from_endpoints(start, end, tz)

if tz is not None:
Expand Down Expand Up @@ -2477,23 +2477,15 @@ def _infer_tz_from_endpoints(
def _maybe_normalize_endpoints(
start: Timestamp | None, end: Timestamp | None, normalize: bool
):
_normalized = True

if start is not None:
if normalize:
if normalize:
if start is not None:
start = start.normalize()
_normalized = True
else:
_normalized = _normalized and start.time() == _midnight

if end is not None:
if normalize:
if end is not None:
end = end.normalize()
_normalized = True
else:
_normalized = _normalized and end.time() == _midnight

return start, end, _normalized
return start, end


def _maybe_localize_point(ts, is_none, is_not_none, freq, tz, ambiguous, nonexistent):
Expand Down