Skip to content
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

[xdoctest][task 330] reformat example code with google style in python/paddle/base/data_feed_desc.py #57137

Merged
merged 9 commits into from
Sep 12, 2023

Conversation

yoyoIcy
Copy link
Contributor

@yoyoIcy yoyoIcy commented Sep 9, 2023

@paddle-bot
Copy link

paddle-bot bot commented Sep 9, 2023

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@paddle-bot paddle-bot bot added the contributor External developers label Sep 9, 2023
Comment on lines 34 to 55
.. code-block:: python

import paddle.base as base
f = open("data.proto", "w")
print >> f, 'name: "MultiSlotDataFeed"'
print >> f, 'batch_size: 2'
print >> f, 'multi_slot_desc {'
print >> f, ' slots {'
print >> f, ' name: "words"'
print >> f, ' type: "uint64"'
print >> f, ' is_dense: false'
print >> f, ' is_used: true'
print >> f, ' }'
print >> f, ' slots {'
print >> f, ' name: "label"'
print >> f, ' type: "uint64"'
print >> f, ' is_dense: false'
print >> f, ' is_used: true'
print >> f, ' }'
print >> f, '}'
f.close()
data_feed = base.DataFeedDesc('data.proto')
>>> import paddle.base as base
>>> f = open("data.proto", "w")
>>> print >> f, 'name: "MultiSlotDataFeed"'
>>> print >> f, 'batch_size: 2'
>>> print >> f, 'multi_slot_desc {'
>>> print >> f, ' slots {'
>>> print >> f, ' name: "words"'
>>> print >> f, ' type: "uint64"'
>>> print >> f, ' is_dense: false'
>>> print >> f, ' is_used: true'
>>> print >> f, ' }'
>>> print >> f, ' slots {'
>>> print >> f, ' name: "label"'
>>> print >> f, ' type: "uint64"'
>>> print >> f, ' is_dense: false'
>>> print >> f, ' is_used: true'
>>> print >> f, ' }'
>>> print >> f, '}'
>>> f.close()
>>> data_feed = base.DataFeedDesc('data.proto')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这段应该不能算是示例,把 .. code-block:: python 改为 .. code-block:: text,原来代码的地方不用加 >>> ,保持原样就行,即使加了也没法运行 ~

Comment on lines 65 to 77
.. code-block:: python

import paddle.base as base
data_feed = base.DataFeedDesc('data.proto')
data_feed.set_batch_size(128)
data_feed.set_dense_slots('wd') # The slot named 'wd' will be dense
data_feed.set_use_slots('wd') # The slot named 'wd' will be used
>>> import paddle.base as base
>>> data_feed = base.DataFeedDesc('data.proto')
>>> data_feed.set_batch_size(128)
>>> data_feed.set_dense_slots('wd') # The slot named 'wd' will be dense
>>> data_feed.set_use_slots('wd') # The slot named 'wd' will be used

Finally, the content can be dumped out for debugging purpose:

.. code-block:: python

print(data_feed.desc())
>>> print(data_feed.desc())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上 ~

Comment on lines 99 to 122
Example:
.. code-block:: python

import paddle.base as base
f = open("data.proto", "w")
print >> f, 'name: "MultiSlotDataFeed"'
print >> f, 'batch_size: 2'
print >> f, 'multi_slot_desc {'
print >> f, ' slots {'
print >> f, ' name: "words"'
print >> f, ' type: "uint64"'
print >> f, ' is_dense: false'
print >> f, ' is_used: true'
print >> f, ' }'
print >> f, ' slots {'
print >> f, ' name: "label"'
print >> f, ' type: "uint64"'
print >> f, ' is_dense: false'
print >> f, ' is_used: true'
print >> f, ' }'
print >> f, '}'
f.close()
data_feed = base.DataFeedDesc('data.proto')
data_feed.set_batch_size(128)
>>> import paddle.base as base
>>> f = open("data.proto", "w")
>>> print >> f, 'name: "MultiSlotDataFeed"'
>>> print >> f, 'batch_size: 2'
>>> print >> f, 'multi_slot_desc {'
>>> print >> f, ' slots {'
>>> print >> f, ' name: "words"'
>>> print >> f, ' type: "uint64"'
>>> print >> f, ' is_dense: false'
>>> print >> f, ' is_used: true'
>>> print >> f, ' }'
>>> print >> f, ' slots {'
>>> print >> f, ' name: "label"'
>>> print >> f, ' type: "uint64"'
>>> print >> f, ' is_dense: false'
>>> print >> f, ' is_used: true'
>>> print >> f, ' }'
>>> print >> f, '}'
>>> f.close()
>>> data_feed = base.DataFeedDesc('data.proto')
>>> data_feed.set_batch_size(128)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果这里作为示例出现的话,需要把里面的这些 print 修改一下,改为正常 python 的写文件语句~

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

统一一下吧,改成可以跑的

我一小时前 review 一半干别的去了,结果回来后你已经 review 了 😂

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

github 时好时坏 ... ... 趁着好用 review 一下 ~

Comment on lines 143 to 163
>>> import paddle.base as base
>>> f = open("data.proto", "w")
>>> print >> f, 'name: "MultiSlotDataFeed"'
>>> print >> f, 'batch_size: 2'
>>> print >> f, 'multi_slot_desc {'
>>> print >> f, ' slots {'
>>> print >> f, ' name: "words"'
>>> print >> f, ' type: "uint64"'
>>> print >> f, ' is_dense: false'
>>> print >> f, ' is_used: true'
>>> print >> f, ' }'
>>> print >> f, ' slots {'
>>> print >> f, ' name: "label"'
>>> print >> f, ' type: "uint64"'
>>> print >> f, ' is_dense: false'
>>> print >> f, ' is_used: true'
>>> print >> f, ' }'
>>> print >> f, '}'
>>> f.close()
>>> data_feed = base.DataFeedDesc('data.proto')
>>> data_feed.set_dense_slots(['words'])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上

Comment on lines 190 to 210
>>> import paddle.base as base
>>> f = open("data.proto", "w")
>>> print >> f, 'name: "MultiSlotDataFeed"'
>>> print >> f, 'batch_size: 2'
>>> print >> f, 'multi_slot_desc {'
>>> print >> f, ' slots {'
>>> print >> f, ' name: "words"'
>>> print >> f, ' type: "uint64"'
>>> print >> f, ' is_dense: false'
>>> print >> f, ' is_used: true'
>>> print >> f, ' }'
>>> print >> f, ' slots {'
>>> print >> f, ' name: "label"'
>>> print >> f, ' type: "uint64"'
>>> print >> f, ' is_dense: false'
>>> print >> f, ' is_used: true'
>>> print >> f, ' }'
>>> print >> f, '}'
>>> f.close()
>>> data_feed = base.DataFeedDesc('data.proto')
>>> data_feed.set_use_slots(['words'])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上

Comment on lines 234 to 254
>>> import paddle.base as base
>>> f = open("data.proto", "w")
>>> print >> f, 'name: "MultiSlotDataFeed"'
>>> print >> f, 'batch_size: 2'
>>> print >> f, 'multi_slot_desc {'
>>> print >> f, ' slots {'
>>> print >> f, ' name: "words"'
>>> print >> f, ' type: "uint64"'
>>> print >> f, ' is_dense: false'
>>> print >> f, ' is_used: true'
>>> print >> f, ' }'
>>> print >> f, ' slots {'
>>> print >> f, ' name: "label"'
>>> print >> f, ' type: "uint64"'
>>> print >> f, ' is_dense: false'
>>> print >> f, ' is_used: true'
>>> print >> f, ' }'
>>> print >> f, '}'
>>> f.close()
>>> data_feed = base.DataFeedDesc('data.proto')
>>> print(data_feed.desc())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上

@@ -33,26 +33,26 @@ class DataFeedDesc:

.. code-block:: python
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

放在 Examples: 之下吧,记得整体加缩进

>>> print >> f, ' }'
>>> print >> f, '}'
>>> f.close()
>>> data_feed = base.DataFeedDesc('data.proto')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这段代码换成 python3 写法吧

with open(xxx) as f:
    f.write('')
    f.write('')

python/paddle/base/data_feed_desc.py Outdated Show resolved Hide resolved
Comment on lines 37 to 55
>>> import paddle.base as base
>>> with open("data.proto", "w") as f:
... f.write('name: "MultiSlotDataFeed"')
... f.write('batch_size: 2')
... f.write('multi_slot_desc {')
... f.write(' slots {')
... f.write(' name: "words"')
... f.write(' type: "uint64"')
... f.write(' is_dense: false')
... f.write(' is_used: true')
... f.write(' }')
... f.write(' slots {')
... f.write(' name: "label"')
... f.write(' type: "uint64"')
... f.write(' is_dense: false')
... f.write(' is_used: true')
... f.write(' }')
... f.write('}')
>>> data_feed = base.DataFeedDesc('data.proto')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

写文件少写了换行符 ~~~ 🤣

... f.write(' is_dense: false')
... f.write(' is_used: true')
... f.write(' }')
... f.write('name: "MultiSlotDataFeed"\\n')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

咦?为啥要 \\n 呀,\\n 最后呈现的不是 \n 么?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image 我在本地用 `\n` 跑不过嘞

Copy link
Member

@SigureMo SigureMo Sep 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我这边试了下可以过呀,直接使用 convert-doctest doctest python/paddle/base/data_feed_desc.py

我这边直接改好啦

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

唔,离谱,CI 报的错和你一样

image

@megemini doctest 怎么把 \n 识别成换行了,唔,奇怪

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

喔喔我知道了

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

convert-doctest 和 CI 提取 docstring 原理不同,一个是字符串裁剪,一个是运行时通过 __doc__ 获取,所以 \n 自然就是换行了,这里用 r raw string 即可两者都能跑(大概?看看 CI 结果)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

正解! \n 在 docstring 中是要用 r

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感谢大佬们!学到嘞~

@luotao1 luotao1 added the HappyOpenSource Pro 进阶版快乐开源活动,更具挑战性的任务 label Sep 11, 2023
Copy link
Member

@SigureMo SigureMo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTMeow 🐾

@luotao1 luotao1 merged commit 7003e17 into PaddlePaddle:develop Sep 12, 2023
@yoyoIcy yoyoIcy deleted the doc330 branch September 12, 2023 12:08
danleifeng pushed a commit to danleifeng/Paddle that referenced this pull request Nov 14, 2023
…n/paddle/base/data_feed_desc.py (PaddlePaddle#57137)

* [Doctest]fix No.330, test=docs_preview

* Update python/paddle/base/data_feed_desc.py

Co-authored-by: Nyakku Shigure <sigure.qaq@gmail.com>

* [Doctest]fix No.330, test=docs_preview

* [Doctest]fix No.330, test=docs_preview

* [Doctest]fix No.330, test=docs_preview

* `\\n` -> `\n`

* use raw string

---------

Co-authored-by: Nyakku Shigure <sigure.qaq@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor External developers HappyOpenSource Pro 进阶版快乐开源活动,更具挑战性的任务
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants