Skip to content

Commit a3af152

Browse files
authored
CoW: Set a bunch of Series copy statements to False (#56520)
1 parent 62f4098 commit a3af152

File tree

5 files changed

+15
-15
lines changed

5 files changed

+15
-15
lines changed

pandas/core/groupby/groupby.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2200,7 +2200,7 @@ def any(self, skipna: bool = True) -> NDFrameT:
22002200
"""
22012201
return self._cython_agg_general(
22022202
"any",
2203-
alt=lambda x: Series(x).any(skipna=skipna),
2203+
alt=lambda x: Series(x, copy=False).any(skipna=skipna),
22042204
skipna=skipna,
22052205
)
22062206

@@ -2257,7 +2257,7 @@ def all(self, skipna: bool = True) -> NDFrameT:
22572257
"""
22582258
return self._cython_agg_general(
22592259
"all",
2260-
alt=lambda x: Series(x).all(skipna=skipna),
2260+
alt=lambda x: Series(x, copy=False).all(skipna=skipna),
22612261
skipna=skipna,
22622262
)
22632263

@@ -2451,7 +2451,7 @@ def mean(
24512451
else:
24522452
result = self._cython_agg_general(
24532453
"mean",
2454-
alt=lambda x: Series(x).mean(numeric_only=numeric_only),
2454+
alt=lambda x: Series(x, copy=False).mean(numeric_only=numeric_only),
24552455
numeric_only=numeric_only,
24562456
)
24572457
return result.__finalize__(self.obj, method="groupby")
@@ -2531,7 +2531,7 @@ def median(self, numeric_only: bool = False) -> NDFrameT:
25312531
"""
25322532
result = self._cython_agg_general(
25332533
"median",
2534-
alt=lambda x: Series(x).median(numeric_only=numeric_only),
2534+
alt=lambda x: Series(x, copy=False).median(numeric_only=numeric_only),
25352535
numeric_only=numeric_only,
25362536
)
25372537
return result.__finalize__(self.obj, method="groupby")
@@ -2640,7 +2640,7 @@ def std(
26402640
else:
26412641
return self._cython_agg_general(
26422642
"std",
2643-
alt=lambda x: Series(x).std(ddof=ddof),
2643+
alt=lambda x: Series(x, copy=False).std(ddof=ddof),
26442644
numeric_only=numeric_only,
26452645
ddof=ddof,
26462646
)
@@ -2747,7 +2747,7 @@ def var(
27472747
else:
27482748
return self._cython_agg_general(
27492749
"var",
2750-
alt=lambda x: Series(x).var(ddof=ddof),
2750+
alt=lambda x: Series(x, copy=False).var(ddof=ddof),
27512751
numeric_only=numeric_only,
27522752
ddof=ddof,
27532753
)
@@ -2977,7 +2977,7 @@ def sem(self, ddof: int = 1, numeric_only: bool = False) -> NDFrameT:
29772977
)
29782978
return self._cython_agg_general(
29792979
"sem",
2980-
alt=lambda x: Series(x).sem(ddof=ddof),
2980+
alt=lambda x: Series(x, copy=False).sem(ddof=ddof),
29812981
numeric_only=numeric_only,
29822982
ddof=ddof,
29832983
)

pandas/core/groupby/ops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ def size(self) -> Series:
707707
out = np.bincount(ids[ids != -1], minlength=ngroups)
708708
else:
709709
out = []
710-
return Series(out, index=self.result_index, dtype="int64")
710+
return Series(out, index=self.result_index, dtype="int64", copy=False)
711711

712712
@cache_readonly
713713
def groups(self) -> dict[Hashable, np.ndarray]:

pandas/core/indexes/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ def _format_duplicate_message(self) -> DataFrame:
723723
assert len(duplicates)
724724

725725
out = (
726-
Series(np.arange(len(self)))
726+
Series(np.arange(len(self)), copy=False)
727727
.groupby(self, observed=False)
728728
.agg(list)[duplicates]
729729
)

pandas/io/sas/sas7bdat.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ def _convert_datetimes(sas_datetimes: pd.Series, unit: str) -> pd.Series:
100100
sas_datetimes._values, unit="s", out_unit="ms"
101101
)
102102
dt64ms = millis.view("M8[ms]") + td
103-
return pd.Series(dt64ms, index=sas_datetimes.index)
103+
return pd.Series(dt64ms, index=sas_datetimes.index, copy=False)
104104
else:
105105
vals = np.array(sas_datetimes, dtype="M8[D]") + td
106-
return pd.Series(vals, dtype="M8[s]", index=sas_datetimes.index)
106+
return pd.Series(vals, dtype="M8[s]", index=sas_datetimes.index, copy=False)
107107

108108

109109
class _Column:
@@ -727,15 +727,15 @@ def _chunk_to_dataframe(self) -> DataFrame:
727727

728728
if self._column_types[j] == b"d":
729729
col_arr = self._byte_chunk[jb, :].view(dtype=self.byte_order + "d")
730-
rslt[name] = pd.Series(col_arr, dtype=np.float64, index=ix)
730+
rslt[name] = pd.Series(col_arr, dtype=np.float64, index=ix, copy=False)
731731
if self.convert_dates:
732732
if self.column_formats[j] in const.sas_date_formats:
733733
rslt[name] = _convert_datetimes(rslt[name], "d")
734734
elif self.column_formats[j] in const.sas_datetime_formats:
735735
rslt[name] = _convert_datetimes(rslt[name], "s")
736736
jb += 1
737737
elif self._column_types[j] == b"s":
738-
rslt[name] = pd.Series(self._string_chunk[js, :], index=ix)
738+
rslt[name] = pd.Series(self._string_chunk[js, :], index=ix, copy=False)
739739
if self.convert_text and (self.encoding is not None):
740740
rslt[name] = self._decode_string(rslt[name].str)
741741
js += 1

pandas/io/stata.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,11 +494,11 @@ def g(x: datetime) -> int:
494494
else:
495495
raise ValueError(f"Format {fmt} is not a known Stata date format")
496496

497-
conv_dates = Series(conv_dates, dtype=np.float64)
497+
conv_dates = Series(conv_dates, dtype=np.float64, copy=False)
498498
missing_value = struct.unpack("<d", b"\x00\x00\x00\x00\x00\x00\xe0\x7f")[0]
499499
conv_dates[bad_loc] = missing_value
500500

501-
return Series(conv_dates, index=index)
501+
return Series(conv_dates, index=index, copy=False)
502502

503503

504504
excessive_string_length_error: Final = """

0 commit comments

Comments
 (0)