Skip to content

Commit 62ab354

Browse files
committed
Address comments
1 parent e010e99 commit 62ab354

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

doc/source/whatsnew/v0.24.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1210,6 +1210,7 @@ Indexing
12101210
- :class:`Index` no longer mangles ``None``, ``NaN`` and ``NaT``, i.e. they are treated as three different keys. However, for numeric Index all three are still coerced to a ``NaN`` (:issue:`22332`)
12111211
- Bug in `scalar in Index` if scalar is a float while the ``Index`` is of integer dtype (:issue:`22085`)
12121212
- Bug in `MultiIndex.set_levels` when levels value is not subscriptable (:issue:`23273`)
1213+
- Bug where setting a timedelta column by ``Index`` causes it to be casted to double, and therefore lose precision (:issue:`23511`)
12131214

12141215
Missing
12151216
^^^^^^^

pandas/tests/indexing/test_timedelta.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,17 @@ def test_numpy_timedelta_scalar_indexing(self, start, stop,
8181
expected = s.iloc[expected_slice]
8282
tm.assert_series_equal(result, expected)
8383

84-
def test_set_dataframe_column_by_index(self):
85-
84+
def test_roundtrip_thru_setitem(self):
85+
# PR 23462
8686
dt1 = pd.Timedelta(0)
8787
dt2 = pd.Timedelta(28767471428571405)
88-
8988
df = pd.DataFrame({'dt': pd.Series([dt1, dt2])})
89+
df_copy = df.copy()
9090
s = pd.Series([dt1])
91-
value_before = df['dt'].iloc[1].value
91+
92+
expected = df['dt'].iloc[1].value
9293
df.loc[[True, False]] = s
93-
value_after = df['dt'].iloc[1].value
94+
result = df['dt'].iloc[1].value
9495

95-
assert value_before == value_after
96+
assert expected == result
97+
tm.assert_frame_equal(df, df_copy)

0 commit comments

Comments
 (0)