Skip to content

Commit

Permalink
Set copy=False when calling pd.Series (#7642)
Browse files Browse the repository at this point in the history
  • Loading branch information
phofl authored Mar 22, 2023
1 parent b836851 commit 019f0b2
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions xarray/core/accessor_dt.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def _access_through_series(values, name):
"""Coerce an array of datetime-like values to a pandas Series and
access requested datetime component
"""
values_as_series = pd.Series(values.ravel())
values_as_series = pd.Series(values.ravel(), copy=False)
if name == "season":
months = values_as_series.dt.month.values
field_values = _season_from_months(months)
Expand Down Expand Up @@ -125,7 +125,7 @@ def _round_through_series_or_index(values, name, freq):
from xarray.coding.cftimeindex import CFTimeIndex

if is_np_datetime_like(values.dtype):
values_as_series = pd.Series(values.ravel())
values_as_series = pd.Series(values.ravel(), copy=False)
method = getattr(values_as_series.dt, name)
else:
values_as_cftimeindex = CFTimeIndex(values.ravel())
Expand Down Expand Up @@ -182,7 +182,7 @@ def _strftime_through_series(values, date_format: str):
"""Coerce an array of datetime-like values to a pandas Series and
apply string formatting
"""
values_as_series = pd.Series(values.ravel())
values_as_series = pd.Series(values.ravel(), copy=False)
strs = values_as_series.dt.strftime(date_format)
return strs.values.reshape(values.shape)

Expand Down
2 changes: 1 addition & 1 deletion xarray/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -1404,7 +1404,7 @@ def first_items(self, index):
)
return grouper.first_items(index)
else:
s = pd.Series(np.arange(index.size), index)
s = pd.Series(np.arange(index.size), index, copy=False)
grouper = pd.Grouper(
freq=self.freq,
closed=self.closed,
Expand Down
2 changes: 1 addition & 1 deletion xarray/core/resample_cftime.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def first_items(self, index: CFTimeIndex):
raise ValueError("Value falls after last bin")

integer_bins = np.searchsorted(index, datetime_bins, side=self.closed)[:-1]
first_items = pd.Series(integer_bins, labels)
first_items = pd.Series(integer_bins, labels, copy=False)

# Mask duplicate values with NaNs, preserving the last values
non_duplicate = ~first_items.duplicated("last")
Expand Down
2 changes: 1 addition & 1 deletion xarray/core/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def _possibly_convert_objects(values):
within the valid date range for ns precision, as pandas will raise an error
if they are not.
"""
as_series = pd.Series(values.ravel())
as_series = pd.Series(values.ravel(), copy=False)
if as_series.dtype.kind in "mM":
as_series = _as_nanosecond_precision(as_series)
return np.asarray(as_series).reshape(values.shape)
Expand Down

0 comments on commit 019f0b2

Please sign in to comment.