Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7595ed5

Browse files
authored
BUG: Fix naive timestamps inheriting timezone from previous timestamps in to_datetime with ISO8601 format (#61400)
1 parent7bb58a8 commit7595ed5

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

‎doc/source/whatsnew/v3.0.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,7 @@ Datetimelike
693693
- Bug in:meth:`to_datetime` on float array with missing values throwing ``FloatingPointError`` (:issue:`58419`)
694694
- Bug in:meth:`to_datetime` on float32 df with year, month, day etc. columns leads to precision issues and incorrect result. (:issue:`60506`)
695695
- Bug in:meth:`to_datetime` reports incorrect index in case of any failure scenario. (:issue:`58298`)
696+
- Bug in:meth:`to_datetime` with ``format="ISO8601"`` and ``utc=True`` where naive timestamps incorrectly inherited timezone offset from previous timestamps in a series. (:issue:`61389`)
696697
- Bug in:meth:`to_datetime` wrongly converts when ``arg`` is a ``np.datetime64`` object with unit of ``ps``. (:issue:`60341`)
697698
- Bug in setting scalar values with mismatched resolution into arrays with non-nanosecond ``datetime64``, ``timedelta64`` or:class:`DatetimeTZDtype` incorrectly truncating those scalars (:issue:`56410`)
698699

‎pandas/_libs/tslibs/strptime.pyx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,9 @@ def array_strptime(
444444
else:
445445
val=str(val)
446446

447+
out_local=0
448+
out_tzoffset=0
449+
447450
if fmt=="ISO8601":
448451
string_to_dts_succeeded=not string_to_dts(
449452
val,&dts,&out_bestunit,&out_local,

‎pandas/tests/tools/test_to_datetime.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3514,6 +3514,54 @@ def test_to_datetime_mixed_not_necessarily_iso8601_coerce():
35143514
tm.assert_index_equal(result,DatetimeIndex(["2020-01-01 00:00:00",NaT]))
35153515

35163516

3517+
deftest_to_datetime_iso8601_utc_single_naive():
3518+
# GH#61389
3519+
result=to_datetime("2023-10-15T14:30:00",utc=True,format="ISO8601")
3520+
expected=Timestamp("2023-10-15 14:30:00+00:00")
3521+
assertresult==expected
3522+
3523+
3524+
deftest_to_datetime_iso8601_utc_mixed_negative_offset():
3525+
# GH#61389
3526+
data= ["2023-10-15T10:30:00-12:00","2023-10-15T14:30:00"]
3527+
result=to_datetime(data,utc=True,format="ISO8601")
3528+
3529+
expected=DatetimeIndex(
3530+
[Timestamp("2023-10-15 22:30:00+00:00"),Timestamp("2023-10-15 14:30:00+00:00")]
3531+
)
3532+
tm.assert_index_equal(result,expected)
3533+
3534+
3535+
deftest_to_datetime_iso8601_utc_mixed_positive_offset():
3536+
# GH#61389
3537+
data= ["2023-10-15T10:30:00+08:00","2023-10-15T14:30:00"]
3538+
result=to_datetime(data,utc=True,format="ISO8601")
3539+
3540+
expected=DatetimeIndex(
3541+
[Timestamp("2023-10-15 02:30:00+00:00"),Timestamp("2023-10-15 14:30:00+00:00")]
3542+
)
3543+
tm.assert_index_equal(result,expected)
3544+
3545+
3546+
deftest_to_datetime_iso8601_utc_mixed_both_offsets():
3547+
# GH#61389
3548+
data= [
3549+
"2023-10-15T10:30:00+08:00",
3550+
"2023-10-15T12:30:00-05:00",
3551+
"2023-10-15T14:30:00",
3552+
]
3553+
result=to_datetime(data,utc=True,format="ISO8601")
3554+
3555+
expected=DatetimeIndex(
3556+
[
3557+
Timestamp("2023-10-15 02:30:00+00:00"),
3558+
Timestamp("2023-10-15 17:30:00+00:00"),
3559+
Timestamp("2023-10-15 14:30:00+00:00"),
3560+
]
3561+
)
3562+
tm.assert_index_equal(result,expected)
3563+
3564+
35173565
deftest_unknown_tz_raises():
35183566
# GH#18702, GH#51476
35193567
dtstr="2014 Jan 9 05:15 FAKE"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp