-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Fix DatetimeIndex.strftime with NaT present #29583
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
Conversation
@@ -473,7 +473,15 @@ def test_strftime(self, datetime_index): | |||
arr = DatetimeArray(datetime_index) | |||
|
|||
result = arr.strftime("%Y %b") | |||
expected = np.array(datetime_index.strftime("%Y %b")) | |||
expected = np.array([ts.strftime("%Y %b") for ts in arr], dtype=object) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change isn't directly related to the PR but something I noticed along the way. I don't think the previous version is completely valid: DatetimeIndex
delegates to DatetimeArray
for strftime
so it was basically testing against itself.
@@ -679,7 +687,15 @@ def test_strftime(self, period_index): | |||
arr = PeriodArray(period_index) | |||
|
|||
result = arr.strftime("%Y") | |||
expected = np.array(period_index.strftime("%Y")) | |||
expected = np.array([per.strftime("%Y") for per in arr], dtype=object) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same thing as my other comment about this pattern for DatetimeArray
.
|
||
def test_strftime_nat(self): | ||
# GH 29578 | ||
arr = PeriodArray(PeriodIndex(["2019-01-01", pd.NaT], dtype="period[D]")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is working fine for PeriodArray
and PeriodIndex
on master; added this test since I didn't see an existing one for this behavior.
thanks @jschendel |
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff