-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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: |
||
tm.assert_numpy_array_equal(result, expected) | ||
|
||
def test_strftime_nat(self): | ||
# GH 29578 | ||
arr = DatetimeArray(DatetimeIndex(["2019-01-01", pd.NaT])) | ||
|
||
result = arr.strftime("%Y-%m-%d") | ||
expected = np.array(["2019-01-01", np.nan], dtype=object) | ||
tm.assert_numpy_array_equal(result, expected) | ||
|
||
|
||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Same thing as my other comment about this pattern for |
||
tm.assert_numpy_array_equal(result, expected) | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. This is working fine for |
||
|
||
result = arr.strftime("%Y-%m-%d") | ||
expected = np.array(["2019-01-01", np.nan], dtype=object) | ||
tm.assert_numpy_array_equal(result, expected) | ||
|
||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.