Skip to content

Commit

Permalink
Backport PR #54625 on branch 2.1.x (BUG: Fix error in printing timezo…
Browse files Browse the repository at this point in the history
…ne series) (#54698)

Backport PR #54625: BUG: Fix error in printing timezone series

Co-authored-by: Adrian D'Alessandro <a.dalessandro@imperial.ac.uk>
  • Loading branch information
meeseeksmachine and AdrianDAlessandro committed Aug 23, 2023
1 parent 503cef4 commit dc27aee
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,7 @@ Datetimelike
- Bug in constructing a :class:`Timestamp` from a string representing a time without a date inferring an incorrect unit (:issue:`54097`)
- Bug in constructing a :class:`Timestamp` with ``ts_input=pd.NA`` raising ``TypeError`` (:issue:`45481`)
- Bug in parsing datetime strings with weekday but no day e.g. "2023 Sept Thu" incorrectly raising ``AttributeError`` instead of ``ValueError`` (:issue:`52659`)
- Bug in the repr for :class:`Series` when dtype is a timezone aware datetime with non-nanosecond resolution raising ``OutOfBoundsDatetime`` (:issue:`54623`)

Timedelta
^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/formats/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -1830,8 +1830,8 @@ def get_format_datetime64_from_values(
class Datetime64TZFormatter(Datetime64Formatter):
def _format_strings(self) -> list[str]:
"""we by definition have a TZ"""
ido = is_dates_only(self.values)
values = self.values.astype(object)
ido = is_dates_only(values)
formatter = self.formatter or get_format_datetime64(
ido, date_format=self.date_format
)
Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/io/formats/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -3320,6 +3320,14 @@ def format_func(x):
result = formatter.get_result()
assert result == ["10:10", "12:12"]

def test_datetime64formatter_tz_ms(self):
x = Series(
np.array(["2999-01-01", "2999-01-02", "NaT"], dtype="datetime64[ms]")
).dt.tz_localize("US/Pacific")
result = fmt.Datetime64TZFormatter(x).get_result()
assert result[0].strip() == "2999-01-01 00:00:00-08:00"
assert result[1].strip() == "2999-01-02 00:00:00-08:00"


class TestNaTFormatting:
def test_repr(self):
Expand Down

0 comments on commit dc27aee

Please sign in to comment.