Skip to content

Commit 140a282

Browse files
Merge pull request #3 from datapythonista/preview_docs
Preview docs
2 parents 2baaaa6 + 7149ac5 commit 140a282

File tree

5 files changed

+54
-0
lines changed

5 files changed

+54
-0
lines changed

.github/workflows/docbuild-and-upload.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,10 @@ jobs:
8989
name: website
9090
path: web/build
9191
retention-days: 14
92+
93+
- name: Trigger web/doc preview
94+
run: curl -X POST https://pandas.pydata.org/preview/submit/$RUN_ID/$PR_ID/
95+
env:
96+
RUN_ID: ${{ github.run_id }}
97+
PR_ID: ${{ github.event.pull_request.number }}
98+
if: github.event_name == 'pull_request'

.github/workflows/preview-docs.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Assign
2+
on:
3+
issue_comment:
4+
types: created
5+
6+
permissions:
7+
contents: read
8+
9+
jobs:
10+
issue_assign:
11+
permissions:
12+
issues: write
13+
pull-requests: write
14+
runs-on: ubuntu-22.04
15+
steps:
16+
- if: github.event.comment.body == '/preview'
17+
run: |
18+
if curl --output /dev/null --silent --head --fail "https://pandas.pydata.org/preview/${{ github.event.issue.number }}"; then
19+
curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -d '{"body": "Website preview of this PR available at: https://pandas.pydata.org/preview/${{ github.event.issue.number }}"}' https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/comments
20+
else
21+
curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -d '{"body": "No preview found for PR ${{ github.event.issue.number }}"}' https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/comments
22+
fi

doc/source/whatsnew/v2.0.0.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,10 @@ Copy-on-Write improvements
246246
a modification to the data happens) when constructing a Series from an existing
247247
Series with the default of ``copy=False`` (:issue:`50471`)
248248

249+
- The :class:`DataFrame` constructor will now create a lazy copy (deferring the copy until
250+
a modification to the data happens) when constructing from an existing
251+
:class:`DataFrame` with the default of ``copy=False`` (:issue:`51239`)
252+
249253
- The :class:`DataFrame` constructor, when constructing a DataFrame from a dictionary
250254
of Series objects and specifying ``copy=False``, will now use a lazy copy
251255
of those Series objects for the columns of the DataFrame (:issue:`50777`)

pandas/core/frame.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,8 @@ def __init__(
656656
data = data.copy(deep=False)
657657

658658
if isinstance(data, (BlockManager, ArrayManager)):
659+
if using_copy_on_write():
660+
data = data.copy(deep=False)
659661
# first check if a Manager is passed without any other arguments
660662
# -> use fastpath (without checking Manager type)
661663
if index is None and columns is None and dtype is None and not copy:

pandas/tests/copy_view/test_constructors.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,25 @@ def test_series_from_series_with_reindex(using_copy_on_write):
8282
assert not result._mgr.blocks[0].refs.has_reference()
8383

8484

85+
@pytest.mark.parametrize("func", [lambda x: x, lambda x: x._mgr])
86+
@pytest.mark.parametrize("columns", [None, ["a"]])
87+
def test_dataframe_constructor_mgr_or_df(using_copy_on_write, columns, func):
88+
df = DataFrame({"a": [1, 2, 3]})
89+
df_orig = df.copy()
90+
91+
new_df = DataFrame(func(df))
92+
93+
assert np.shares_memory(get_array(df, "a"), get_array(new_df, "a"))
94+
new_df.iloc[0] = 100
95+
96+
if using_copy_on_write:
97+
assert not np.shares_memory(get_array(df, "a"), get_array(new_df, "a"))
98+
tm.assert_frame_equal(df, df_orig)
99+
else:
100+
assert np.shares_memory(get_array(df, "a"), get_array(new_df, "a"))
101+
tm.assert_frame_equal(df, new_df)
102+
103+
85104
@pytest.mark.parametrize("dtype", [None, "int64", "Int64"])
86105
@pytest.mark.parametrize("index", [None, [0, 1, 2]])
87106
@pytest.mark.parametrize("columns", [None, ["a", "b"], ["a", "b", "c"]])

0 commit comments

Comments
 (0)