Skip to content
This repository was archived by the owner on Feb 2, 2024. It is now read-only.

Commit 751c037

Browse files
authored
Doc for df getitem (#665)
* add examples for df.getitem * delete extension columns in examples * add doc for df.getitem * change doc & examples * change doc * doc for DF.getitem * delete extension blank lines * not use if_else * change in apiref_generator * add description
1 parent 07b70ca commit 751c037

10 files changed

+402
-4
lines changed

docs/source/_templates/_api_ref.pandas.dataframe_templ.rst

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Attributes/Operators
3131
DataFrame.shape
3232
DataFrame.memory_usage
3333
DataFrame.empty
34+
DataFrame.getitem
3435
3536
Type Conversions
3637
----------------

docs/source/buildscripts/apiref_generator.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,16 @@ def generate_simple_object_doc(pandas_name, short_doc_flag=False, doc_from_panda
422422
if pandas_obj is None:
423423
return doc # Empty documentation for no-object
424424

425+
# Here if additional sections from Intel SDC object needs to be added to pandas_obj docstring
426+
sdc_obj = get_sdc_object_by_pandas_name(pandas_name)
427+
428+
if pandas_obj == 0:
429+
# there is no Pandas documentation, documentation is fully generated from SDC docstring
430+
doc_from_pandas_flag = False
431+
if short_doc_flag:
432+
doc = get_short_description(sdc_obj, sdc_header_flag=True)
433+
return reformat(doc)
434+
425435
if doc_from_pandas_flag: # Check if documentation needs to be generated from Pandas docstring
426436
if short_doc_flag: # Check if only short description is needed
427437
doc = get_short_description(pandas_obj) # Short description is requested
@@ -459,8 +469,6 @@ def generate_simple_object_doc(pandas_name, short_doc_flag=False, doc_from_panda
459469
else:
460470
return doc
461471

462-
# Here if additional sections from Intel SDC object needs to be added to pandas_obj docstring
463-
sdc_obj = get_sdc_object_by_pandas_name(pandas_name)
464472
if sdc_obj is None:
465473
if unsupported_warning:
466474
if reformat_pandas:
@@ -491,7 +499,10 @@ def generate_simple_object_doc(pandas_name, short_doc_flag=False, doc_from_panda
491499
indent = get_indent(doc)
492500
for title, text in sdc_doc:
493501
if title.strip() == '':
494-
doc += '\n' + reindent(text, indent)
502+
if pandas_obj == 0:
503+
doc += reindent(text, indent) + '\n'
504+
else:
505+
doc += '\n' + reindent(text, indent)
495506
else:
496507
doc += '\n' + reindent(create_heading_str(title), indent) + '\n' + \
497508
reindent(text, indent) + '\n'

docs/source/buildscripts/sdc_object_utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def get_obj(obj_name):
176176

177177
split_name.pop(0)
178178
for name in split_name:
179-
split_obj = getattr(split_obj, name)
179+
split_obj = getattr(split_obj, name, 0)
180180

181181
return split_obj
182182

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# *****************************************************************************
2+
# Copyright (c) 2020, Intel Corporation All rights reserved.
3+
#
4+
# Redistribution and use in source and binary forms, with or without
5+
# modification, are permitted provided that the following conditions are met:
6+
#
7+
# Redistributions of source code must retain the above copyright notice,
8+
# this list of conditions and the following disclaimer.
9+
#
10+
# Redistributions in binary form must reproduce the above copyright notice,
11+
# this list of conditions and the following disclaimer in the documentation
12+
# and/or other materials provided with the distribution.
13+
#
14+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17+
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
18+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20+
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21+
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22+
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23+
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
24+
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25+
# *****************************************************************************
26+
27+
"""
28+
Expected result:
29+
0 0
30+
1 1
31+
2 2
32+
3 3
33+
4 4
34+
Name: A, dtype: int64
35+
"""
36+
37+
import pandas as pd
38+
from numba import njit
39+
40+
41+
@njit
42+
def dataframe_getitem():
43+
df = pd.DataFrame({'A': [0, 1, 2, 3, 4],
44+
'B': [1, 2, 3, 4, 5],
45+
'C': [2, 3, 4, 5, 6]})
46+
47+
return df['A']
48+
49+
50+
print(dataframe_getitem())
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# *****************************************************************************
2+
# Copyright (c) 2020, Intel Corporation All rights reserved.
3+
#
4+
# Redistribution and use in source and binary forms, with or without
5+
# modification, are permitted provided that the following conditions are met:
6+
#
7+
# Redistributions of source code must retain the above copyright notice,
8+
# this list of conditions and the following disclaimer.
9+
#
10+
# Redistributions in binary form must reproduce the above copyright notice,
11+
# this list of conditions and the following disclaimer in the documentation
12+
# and/or other materials provided with the distribution.
13+
#
14+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17+
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
18+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20+
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21+
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22+
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23+
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
24+
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25+
# *****************************************************************************
26+
27+
"""
28+
Expected result:
29+
A B C
30+
1 1 2 3
31+
4 4 5 6
32+
"""
33+
34+
import pandas as pd
35+
import numpy as np
36+
from numba import njit
37+
38+
39+
@njit
40+
def dataframe_getitem():
41+
df = pd.DataFrame({'A': [0, 1, 2, 3, 4],
42+
'B': [1, 2, 3, 4, 5],
43+
'C': [2, 3, 4, 5, 6]})
44+
arr = np.array([False, True, False, False, True])
45+
46+
return df[arr]
47+
48+
49+
print(dataframe_getitem())
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# *****************************************************************************
2+
# Copyright (c) 2020, Intel Corporation All rights reserved.
3+
#
4+
# Redistribution and use in source and binary forms, with or without
5+
# modification, are permitted provided that the following conditions are met:
6+
#
7+
# Redistributions of source code must retain the above copyright notice,
8+
# this list of conditions and the following disclaimer.
9+
#
10+
# Redistributions in binary form must reproduce the above copyright notice,
11+
# this list of conditions and the following disclaimer in the documentation
12+
# and/or other materials provided with the distribution.
13+
#
14+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17+
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
18+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20+
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21+
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22+
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23+
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
24+
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25+
# *****************************************************************************
26+
27+
"""
28+
Expected result:
29+
0 2
30+
1 3
31+
2 4
32+
3 5
33+
4 6
34+
Name: C, dtype: int64
35+
"""
36+
37+
import pandas as pd
38+
from numba import njit
39+
40+
41+
@njit
42+
def dataframe_getitem():
43+
df = pd.DataFrame({'A': [0, 1, 2, 3, 4],
44+
'B': [1, 2, 3, 4, 5],
45+
'C': [2, 3, 4, 5, 6]})
46+
47+
return df.C
48+
49+
50+
print(dataframe_getitem())
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# *****************************************************************************
2+
# Copyright (c) 2020, Intel Corporation All rights reserved.
3+
#
4+
# Redistribution and use in source and binary forms, with or without
5+
# modification, are permitted provided that the following conditions are met:
6+
#
7+
# Redistributions of source code must retain the above copyright notice,
8+
# this list of conditions and the following disclaimer.
9+
#
10+
# Redistributions in binary form must reproduce the above copyright notice,
11+
# this list of conditions and the following disclaimer in the documentation
12+
# and/or other materials provided with the distribution.
13+
#
14+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17+
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
18+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20+
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21+
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22+
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23+
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
24+
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25+
# *****************************************************************************
26+
27+
"""
28+
Expected result:
29+
A B C
30+
0 0 1 2
31+
2 2 3 4
32+
"""
33+
34+
import pandas as pd
35+
from numba import njit
36+
37+
38+
@njit
39+
def dataframe_getitem():
40+
df = pd.DataFrame({'A': [0, 1, 2, 3, 4],
41+
'B': [1, 2, 3, 4, 5],
42+
'C': [2, 3, 4, 5, 6]})
43+
val = pd.Series([True, False, True])
44+
45+
return df[val]
46+
47+
48+
print(dataframe_getitem())
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# *****************************************************************************
2+
# Copyright (c) 2020, Intel Corporation All rights reserved.
3+
#
4+
# Redistribution and use in source and binary forms, with or without
5+
# modification, are permitted provided that the following conditions are met:
6+
#
7+
# Redistributions of source code must retain the above copyright notice,
8+
# this list of conditions and the following disclaimer.
9+
#
10+
# Redistributions in binary form must reproduce the above copyright notice,
11+
# this list of conditions and the following disclaimer in the documentation
12+
# and/or other materials provided with the distribution.
13+
#
14+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17+
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
18+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20+
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21+
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22+
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23+
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
24+
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25+
# *****************************************************************************
26+
27+
"""
28+
Expected result:
29+
A B C
30+
1 1 2 3
31+
2 2 3 4
32+
"""
33+
34+
import pandas as pd
35+
from numba import njit
36+
37+
38+
@njit
39+
def dataframe_getitem():
40+
df = pd.DataFrame({'A': [0, 1, 2, 3, 4],
41+
'B': [1, 2, 3, 4, 5],
42+
'C': [2, 3, 4, 5, 6]})
43+
44+
return df[1:3]
45+
46+
47+
print(dataframe_getitem())
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# *****************************************************************************
2+
# Copyright (c) 2020, Intel Corporation All rights reserved.
3+
#
4+
# Redistribution and use in source and binary forms, with or without
5+
# modification, are permitted provided that the following conditions are met:
6+
#
7+
# Redistributions of source code must retain the above copyright notice,
8+
# this list of conditions and the following disclaimer.
9+
#
10+
# Redistributions in binary form must reproduce the above copyright notice,
11+
# this list of conditions and the following disclaimer in the documentation
12+
# and/or other materials provided with the distribution.
13+
#
14+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17+
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
18+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20+
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21+
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22+
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23+
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
24+
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25+
# *****************************************************************************
26+
27+
"""
28+
Expected result:
29+
A C
30+
0 0 2
31+
1 1 3
32+
2 2 4
33+
3 3 5
34+
4 4 6
35+
"""
36+
37+
import pandas as pd
38+
from numba import njit
39+
40+
41+
@njit
42+
def dataframe_getitem():
43+
df = pd.DataFrame({'A': [0, 1, 2, 3, 4],
44+
'B': [1, 2, 3, 4, 5],
45+
'C': [2, 3, 4, 5, 6]})
46+
47+
return df[('A', 'C')]
48+
49+
50+
print(dataframe_getitem())

0 commit comments

Comments
 (0)