Skip to content

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

Merged
merged 1 commit into from
Nov 13, 2019

Conversation

jschendel
Copy link
Member

@jschendel jschendel added Bug Datetime Datetime data dtype Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate labels Nov 13, 2019
@jschendel jschendel added this to the 1.0 milestone Nov 13, 2019
@@ -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)
Copy link
Member Author

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)
Copy link
Member Author

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]"))
Copy link
Member Author

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.

@jreback jreback merged commit 2064876 into pandas-dev:master Nov 13, 2019
@jreback
Copy link
Contributor

jreback commented Nov 13, 2019

thanks @jschendel

@jschendel jschendel deleted the dti-strftime-nan branch November 13, 2019 17:17
Reksbril pushed a commit to Reksbril/pandas that referenced this pull request Nov 18, 2019
proost pushed a commit to proost/pandas that referenced this pull request Dec 19, 2019
proost pushed a commit to proost/pandas that referenced this pull request Dec 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Datetime Datetime data dtype Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: DatetimeIndex.strftime converts NaT to string 'NaT'
3 participants