Skip to content

Commit

Permalink
Backport PR #52982 on branch 2.0.x (BUG: Have non nano rounding noop …
Browse files Browse the repository at this point in the history
…return copy) (#53004)

Backport PR #52982: BUG: Have non nano rounding noop return copy

Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com>
  • Loading branch information
meeseeksmachine and mroeschke committed Apr 29, 2023
1 parent 8475f2f commit bfe810b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pandas/core/arrays/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -2010,7 +2010,7 @@ def _round(self, freq, mode, ambiguous, nonexistent):
nanos = delta_to_nanoseconds(offset, self._creso)
if nanos == 0:
# GH 52761
return self
return self.copy()
result_i8 = round_nsint64(values, mode, nanos)
result = self._maybe_mask_results(result_i8, fill_value=iNaT)
result = result.view(self._ndarray.dtype)
Expand Down
2 changes: 2 additions & 0 deletions pandas/tests/series/accessors/test_dt_accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,8 @@ def test_dt_round_nonnano_higher_resolution_no_op(self, freq):
result = ser.dt.round(freq)
tm.assert_series_equal(result, expected)

assert not np.shares_memory(ser.array._ndarray, result.array._ndarray)

def test_dt_namespace_accessor_categorical(self):
# GH 19468
dti = DatetimeIndex(["20171111", "20181212"]).repeat(2)
Expand Down

0 comments on commit bfe810b

Please sign in to comment.