Skip to content

Commit 926a3cf

Browse files
committed
move variable creation to common variable
1 parent e828f24 commit 926a3cf

File tree

1 file changed

+40
-224
lines changed

1 file changed

+40
-224
lines changed

pandas/core/ops/docstrings.py

+40-224
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def _make_flex_doc(op_name, typ):
5353
return doc
5454

5555

56-
_add_example_SERIES = """
56+
_common_examples_SERIES = """
5757
Examples
5858
--------
5959
>>> a = pd.Series([1, 1, 1, np.nan], index=['a', 'b', 'c', 'd'])
@@ -69,33 +69,39 @@ def _make_flex_doc(op_name, typ):
6969
b NaN
7070
d 1.0
7171
e NaN
72-
dtype: float64
73-
>>> a.add(b, fill_value=0)
74-
a 2.0
75-
b 1.0
76-
c 1.0
77-
d 1.0
78-
e NaN
79-
dtype: float64
80-
"""
72+
dtype: float64"""
8173

82-
_sub_example_SERIES = """
74+
_common_examples_comparison_SERIES = """
8375
Examples
8476
--------
85-
>>> a = pd.Series([1, 1, 1, np.nan], index=['a', 'b', 'c', 'd'])
77+
>>> a = pd.Series([1, 1, 1, np.nan, 1], index=['a', 'b', 'c', 'd', 'e'])
8678
>>> a
8779
a 1.0
8880
b 1.0
8981
c 1.0
9082
d NaN
83+
e 1.0
9184
dtype: float64
92-
>>> b = pd.Series([1, np.nan, 1, np.nan], index=['a', 'b', 'd', 'e'])
85+
>>> b = pd.Series([0, 1, 2, np.nan, 1], index=['a', 'b', 'c', 'd', 'f'])
9386
>>> b
94-
a 1.0
95-
b NaN
87+
a 0.0
88+
b 1.0
89+
c 2.0
90+
d NaN
91+
f 1.0
92+
dtype: float64"""
93+
94+
_add_example_SERIES = _common_examples_SERIES + """
95+
>>> a.add(b, fill_value=0)
96+
a 2.0
97+
b 1.0
98+
c 1.0
9699
d 1.0
97100
e NaN
98101
dtype: float64
102+
"""
103+
104+
_sub_example_SERIES = _common_examples_SERIES + """
99105
>>> a.subtract(b, fill_value=0)
100106
a 0.0
101107
b 1.0
@@ -105,23 +111,7 @@ def _make_flex_doc(op_name, typ):
105111
dtype: float64
106112
"""
107113

108-
_mul_example_SERIES = """
109-
Examples
110-
--------
111-
>>> a = pd.Series([1, 1, 1, np.nan], index=['a', 'b', 'c', 'd'])
112-
>>> a
113-
a 1.0
114-
b 1.0
115-
c 1.0
116-
d NaN
117-
dtype: float64
118-
>>> b = pd.Series([1, np.nan, 1, np.nan], index=['a', 'b', 'd', 'e'])
119-
>>> b
120-
a 1.0
121-
b NaN
122-
d 1.0
123-
e NaN
124-
dtype: float64
114+
_mul_example_SERIES = _common_examples_SERIES + """
125115
>>> a.multiply(b, fill_value=0)
126116
a 1.0
127117
b 0.0
@@ -131,23 +121,7 @@ def _make_flex_doc(op_name, typ):
131121
dtype: float64
132122
"""
133123

134-
_div_example_SERIES = """
135-
Examples
136-
--------
137-
>>> a = pd.Series([1, 1, 1, np.nan], index=['a', 'b', 'c', 'd'])
138-
>>> a
139-
a 1.0
140-
b 1.0
141-
c 1.0
142-
d NaN
143-
dtype: float64
144-
>>> b = pd.Series([1, np.nan, 1, np.nan], index=['a', 'b', 'd', 'e'])
145-
>>> b
146-
a 1.0
147-
b NaN
148-
d 1.0
149-
e NaN
150-
dtype: float64
124+
_div_example_SERIES = _common_examples_SERIES + """
151125
>>> a.divide(b, fill_value=0)
152126
a 1.0
153127
b inf
@@ -157,23 +131,7 @@ def _make_flex_doc(op_name, typ):
157131
dtype: float64
158132
"""
159133

160-
_floordiv_example_SERIES = """
161-
Examples
162-
--------
163-
>>> a = pd.Series([1, 1, 1, np.nan], index=['a', 'b', 'c', 'd'])
164-
>>> a
165-
a 1.0
166-
b 1.0
167-
c 1.0
168-
d NaN
169-
dtype: float64
170-
>>> b = pd.Series([1, np.nan, 1, np.nan], index=['a', 'b', 'd', 'e'])
171-
>>> b
172-
a 1.0
173-
b NaN
174-
d 1.0
175-
e NaN
176-
dtype: float64
134+
_floordiv_example_SERIES = _common_examples_SERIES + """
177135
>>> a.floordiv(b, fill_value=0)
178136
a 1.0
179137
b NaN
@@ -183,23 +141,7 @@ def _make_flex_doc(op_name, typ):
183141
dtype: float64
184142
"""
185143

186-
_mod_example_SERIES = """
187-
Examples
188-
--------
189-
>>> a = pd.Series([1, 1, 1, np.nan], index=['a', 'b', 'c', 'd'])
190-
>>> a
191-
a 1.0
192-
b 1.0
193-
c 1.0
194-
d NaN
195-
dtype: float64
196-
>>> b = pd.Series([1, np.nan, 1, np.nan], index=['a', 'b', 'd', 'e'])
197-
>>> b
198-
a 1.0
199-
b NaN
200-
d 1.0
201-
e NaN
202-
dtype: float64
144+
_mod_example_SERIES = _common_examples_SERIES + """
203145
>>> a.mod(b, fill_value=0)
204146
a 0.0
205147
b NaN
@@ -208,23 +150,7 @@ def _make_flex_doc(op_name, typ):
208150
e NaN
209151
dtype: float64
210152
"""
211-
_pow_example_SERIES = """
212-
Examples
213-
--------
214-
>>> a = pd.Series([1, 1, 1, np.nan], index=['a', 'b', 'c', 'd'])
215-
>>> a
216-
a 1.0
217-
b 1.0
218-
c 1.0
219-
d NaN
220-
dtype: float64
221-
>>> b = pd.Series([1, np.nan, 1, np.nan], index=['a', 'b', 'd', 'e'])
222-
>>> b
223-
a 1.0
224-
b NaN
225-
d 1.0
226-
e NaN
227-
dtype: float64
153+
_pow_example_SERIES = _common_examples_SERIES + """
228154
>>> a.pow(b, fill_value=0)
229155
a 1.0
230156
b 1.0
@@ -234,83 +160,27 @@ def _make_flex_doc(op_name, typ):
234160
dtype: float64
235161
"""
236162

237-
_ne_example_SERIES = """
238-
Examples
239-
--------
240-
>>> a = pd.Series([1, 1, np.nan, np.nan, 0], index=['a', 'b', 'c', 'd', 'e'])
241-
>>> a
242-
a 1.0
243-
b 1.0
244-
c 1.0
245-
d NaN
246-
e 1.0
247-
dtype: float64
248-
>>> b = pd.Series([0, 1, np.nan, 0, 1], index=['a', 'b', 'c', 'd', 'f'])
249-
>>> b
250-
a 0.0
251-
b 1.0
252-
c 2.0
253-
d NaN
254-
f 1.0
255-
dtype: float64
163+
_ne_example_SERIES = _common_examples_SERIES + """
256164
>>> a.ne(b, fill_value=0)
257-
a True
258-
b False
165+
a False
166+
b True
259167
c True
260-
d False
261-
e False
262-
f True
168+
d True
169+
e True
263170
dtype: bool
264171
"""
265172

266-
_eq_example_SERIES = """
267-
Examples
268-
--------
269-
>>> a = pd.Series([1, 1, np.nan, np.nan, 0], index=['a', 'b', 'c', 'd', 'e'])
270-
>>> a
271-
a 1.0
272-
b 1.0
273-
c 1.0
274-
d NaN
275-
e 1.0
276-
dtype: float64
277-
>>> b = pd.Series([0, 1, np.nan, 0, 1], index=['a', 'b', 'c', 'd', 'f'])
278-
>>> b
279-
a 0.0
280-
b 1.0
281-
c 2.0
282-
d NaN
283-
f 1.0
284-
dtype: float64
173+
_eq_example_SERIES = _common_examples_SERIES + """
285174
>>> a.eq(b, fill_value=0)
286-
a False
287-
b True
175+
a True
176+
b False
288177
c False
289-
d True
290-
e True
291-
f False
178+
d False
179+
e False
292180
dtype: bool
293181
"""
294182

295-
_lt_example_SERIES = """
296-
Examples
297-
--------
298-
>>> a = pd.Series([1, 1, 1, np.nan, 1], index=['a', 'b', 'c', 'd', 'e'])
299-
>>> a
300-
a 1.0
301-
b 1.0
302-
c 1.0
303-
d NaN
304-
e 1.0
305-
dtype: float64
306-
>>> b = pd.Series([0, 1, 2, np.nan, 1], index=['a', 'b', 'c', 'd', 'f'])
307-
>>> b
308-
a 0.0
309-
b 1.0
310-
c 2.0
311-
d NaN
312-
f 1.0
313-
dtype: float64
183+
_lt_example_SERIES = _common_examples_comparison_SERIES + """
314184
>>> a.lt(b, fill_value=0)
315185
a False
316186
b False
@@ -321,25 +191,7 @@ def _make_flex_doc(op_name, typ):
321191
dtype: bool
322192
"""
323193

324-
_le_example_SERIES = """
325-
Examples
326-
--------
327-
>>> a = pd.Series([1, 1, 1, np.nan, 1], index=['a', 'b', 'c', 'd', 'e'])
328-
>>> a
329-
a 1.0
330-
b 1.0
331-
c 1.0
332-
d NaN
333-
e 1.0
334-
dtype: float64
335-
>>> b = pd.Series([0, 1, 2, np.nan, 1], index=['a', 'b', 'c', 'd', 'f'])
336-
>>> b
337-
a 0.0
338-
b 1.0
339-
c 2.0
340-
d NaN
341-
f 1.0
342-
dtype: float64
194+
_le_example_SERIES = _common_examples_comparison_SERIES + """
343195
>>> a.le(b, fill_value=0)
344196
a False
345197
b True
@@ -350,25 +202,7 @@ def _make_flex_doc(op_name, typ):
350202
dtype: bool
351203
"""
352204

353-
_gt_example_SERIES = """
354-
Examples
355-
--------
356-
>>> a = pd.Series([1, 1, 1, np.nan, 1], index=['a', 'b', 'c', 'd', 'e'])
357-
>>> a
358-
a 1.0
359-
b 1.0
360-
c 1.0
361-
d NaN
362-
e 1.0
363-
dtype: float64
364-
>>> b = pd.Series([0, 1, 2, np.nan, 1], index=['a', 'b', 'c', 'd', 'f'])
365-
>>> b
366-
a 0.0
367-
b 1.0
368-
c 2.0
369-
d NaN
370-
f 1.0
371-
dtype: float64
205+
_gt_example_SERIES = _common_examples_comparison_SERIES + """
372206
>>> a.gt(b, fill_value=0)
373207
a True
374208
b False
@@ -379,25 +213,7 @@ def _make_flex_doc(op_name, typ):
379213
dtype: bool
380214
"""
381215

382-
_ge_example_SERIES = """
383-
Examples
384-
--------
385-
>>> a = pd.Series([1, 1, 1, np.nan, 1], index=['a', 'b', 'c', 'd', 'e'])
386-
>>> a
387-
a 1.0
388-
b 1.0
389-
c 1.0
390-
d NaN
391-
e 1.0
392-
dtype: float64
393-
>>> b = pd.Series([0, 1, 2, np.nan, 1], index=['a', 'b', 'c', 'd', 'f'])
394-
>>> b
395-
a 0.0
396-
b 1.0
397-
c 2.0
398-
d NaN
399-
f 1.0
400-
dtype: float64
216+
_ge_example_SERIES = _common_examples_comparison_SERIES + """
401217
>>> a.ge(b, fill_value=0)
402218
a True
403219
b True

0 commit comments

Comments
 (0)