Skip to content

Set copy=False when calling pd.Series #7642

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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