8000 BUG: preserve fold in Timestamp.replace by AlexKirko · Pull Request #37644 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

BUG: preserve fold in Timestamp.replace #37644

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 9 commits into from
Nov 8, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conve 8000 rsations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
TST: incorporate reviewer suggestions
  • Loading branch information
AlexKirko committed Nov 5, 2020
commit 2ca31caa7f6f49a16a282efd8efeb6f9a50461ee
11 changes: 5 additions & 6 deletions pandas/tests/scalar/timestamp/test_unary_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,13 +426,12 @@ def test_timestamp(self):
assert dt.timestamp() == ts.timestamp()


def test_replace_preserves_fold():
@pytest.mark.parametrize("fold", [0, 1])
def test_replace_preserves_fold(fold):
# GH 37610. Check that replace preserves Timestamp fold property
tz = gettz("Europe/Moscow")

dt = datetime(year=2009, month=10, day=25, hour=2, minute=30, fold=1, tzinfo=tz)
ts = Timestamp(year=2009, month=10, day=25, hour=2, minute=30, fold=1, tz=tz)
result = ts.replace(tzinfo=tz).fold
expected = dt.replace(tzinfo=tz).fold
ts = Timestamp(year=2009, month=10, day=25, hour=2, minute=30, fold=fold, tz=tz)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why tz= instead of tzinfo=? I seem to remember that there are vague plans to remove tz= as redundant or something?

Copy link
Member

Choose a reason for hiding this comment

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

tz kwarg allows for a string whereas tzinfo requires a tzinfo object

Copy link
Contributor

Choose a reason for hiding this comment

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

But that's not what's happening here...

Copy link
Member Author
@AlexKirko AlexKirko Nov 6, 2020

Choose a reason for hiding this comment

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

Thanks, agreed. Passing a tzinfo object into the tz argument gives the same result (as all tzinfo gives us is a Cython type-check before we set tz, tzinfo = tzinfo, None), but passing tzinfo is more readable and doc-compliant.
Changed it, please take a look.

ts_replaced = ts.replace(tzinfo=tz)

assert result == expected
assert ts_replaced.fold == fold
0