Skip to content

Commit a38a583

Browse files
BUG: Fix error in printing timezone series (#54625)
* Check is_dates_only with datetime array in Datetime64TZFormatter * Add entry in doc/source/whatsnew/v2.1.0.rst
1 parent 563aad3 commit a38a583

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

doc/source/whatsnew/v2.1.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,7 @@ Datetimelike
667667
- Bug in constructing a :class:`Timestamp` from a string representing a time without a date inferring an incorrect unit (:issue:`54097`)
668668
- Bug in constructing a :class:`Timestamp` with ``ts_input=pd.NA`` raising ``TypeError`` (:issue:`45481`)
669669
- Bug in parsing datetime strings with weekday but no day e.g. "2023 Sept Thu" incorrectly raising ``AttributeError`` instead of ``ValueError`` (:issue:`52659`)
670+
- Bug in the repr for :class:`Series` when dtype is a timezone aware datetime with non-nanosecond resolution raising ``OutOfBoundsDatetime`` (:issue:`54623`)
670671

671672
Timedelta
672673
^^^^^^^^^

pandas/io/formats/format.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1830,8 +1830,8 @@ def get_format_datetime64_from_values(
18301830
class Datetime64TZFormatter(Datetime64Formatter):
18311831
def _format_strings(self) -> list[str]:
18321832
"""we by definition have a TZ"""
1833+
ido = is_dates_only(self.values)
18331834
values = self.values.astype(object)
1834-
ido = is_dates_only(values)
18351835
formatter = self.formatter or get_format_datetime64(
18361836
ido, date_format=self.date_format
18371837
)

pandas/tests/io/formats/test_format.py

+8
Original file line numberDiff line numberDiff line change
@@ -3320,6 +3320,14 @@ def format_func(x):
33203320
result = formatter.get_result()
33213321
assert result == ["10:10", "12:12"]
33223322

3323+
def test_datetime64formatter_tz_ms(self):
3324+
x = Series(
3325+
np.array(["2999-01-01", "2999-01-02", "NaT"], dtype="datetime64[ms]")
3326+
).dt.tz_localize("US/Pacific")
3327+
result = fmt.Datetime64TZFormatter(x).get_result()
3328+
assert result[0].strip() == "2999-01-01 00:00:00-08:00"
3329+
assert result[1].strip() == "2999-01-02 00:00:00-08:00"
3330+
33233331

33243332
class TestNaTFormatting:
33253333
def test_repr(self):

0 commit comments

Comments
 (0)