Skip to content

Commit 48e600b

Browse files
authored
CoW: Set copy=False explicitly internally for Series and DataFrame in io/pytables (#52032)
1 parent 396ef60 commit 48e600b

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

pandas/io/pytables.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3126,7 +3126,7 @@ def read(
31263126
self.validate_read(columns, where)
31273127
index = self.read_index("index", start=start, stop=stop)
31283128
values = self.read_array("values", start=start, stop=stop)
3129-
return Series(values, index=index, name=self.name)
3129+
return Series(values, index=index, name=self.name, copy=False)
31303130

31313131
# error: Signature of "write" incompatible with supertype "Fixed"
31323132
def write(self, obj, **kwargs) -> None: # type: ignore[override]
@@ -3193,7 +3193,7 @@ def read(
31933193
values = self.read_array(f"block{i}_values", start=_start, stop=_stop)
31943194

31953195
columns = items[items.get_indexer(blk_items)]
3196-
df = DataFrame(values.T, columns=columns, index=axes[1])
3196+
df = DataFrame(values.T, columns=columns, index=axes[1], copy=False)
31973197
dfs.append(df)
31983198

31993199
if len(dfs) > 0:
@@ -3461,7 +3461,7 @@ def write_metadata(self, key: str, values: np.ndarray) -> None:
34613461
"""
34623462
self.parent.put(
34633463
self._get_metadata_path(key),
3464-
Series(values),
3464+
Series(values, copy=False),
34653465
format="table",
34663466
encoding=self.encoding,
34673467
errors=self.errors,
@@ -4221,7 +4221,7 @@ def read_column(
42214221
encoding=self.encoding,
42224222
errors=self.errors,
42234223
)
4224-
return Series(_set_tz(col_values[1], a.tz), name=column)
4224+
return Series(_set_tz(col_values[1], a.tz), name=column, copy=False)
42254225

42264226
raise KeyError(f"column [{column}] not found in the table")
42274227

@@ -4448,7 +4448,7 @@ def delete(self, where=None, start: int | None = None, stop: int | None = None):
44484448
values = selection.select_coords()
44494449

44504450
# delete the rows in reverse order
4451-
sorted_series = Series(values).sort_values()
4451+
sorted_series = Series(values, copy=False).sort_values()
44524452
ln = len(sorted_series)
44534453

44544454
if ln:
@@ -4561,7 +4561,7 @@ def read(
45614561
values = values.reshape((1, values.shape[0]))
45624562

45634563
if isinstance(values, np.ndarray):
4564-
df = DataFrame(values.T, columns=cols_, index=index_)
4564+
df = DataFrame(values.T, columns=cols_, index=index_, copy=False)
45654565
elif isinstance(values, Index):
45664566
df = DataFrame(values, columns=cols_, index=index_)
45674567
else:
@@ -5017,7 +5017,7 @@ def _convert_string_array(data: np.ndarray, encoding: str, errors: str) -> np.nd
50175017
# encode if needed
50185018
if len(data):
50195019
data = (
5020-
Series(data.ravel())
5020+
Series(data.ravel(), copy=False)
50215021
.str.encode(encoding, errors)
50225022
._values.reshape(data.shape)
50235023
)
@@ -5057,7 +5057,7 @@ def _unconvert_string_array(
50575057
dtype = f"U{itemsize}"
50585058

50595059
if isinstance(data[0], bytes):
5060-
data = Series(data).str.decode(encoding, errors=errors)._values
5060+
data = Series(data, copy=False).str.decode(encoding, errors=errors)._values
50615061
else:
50625062
data = data.astype(dtype, copy=False).astype(object, copy=False)
50635063

0 commit comments

Comments
 (0)