Skip to content

Commit d632cd0

Browse files
authored
docs: update struct examples. (#953)
* docs:update struct examples. * format fix
1 parent 2b0f0fa commit d632cd0

File tree

1 file changed

+22
-22
lines changed
  • third_party/bigframes_vendored/pandas/core/arrays/arrow

1 file changed

+22
-22
lines changed

third_party/bigframes_vendored/pandas/core/arrays/arrow/accessors.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ def field(self, name_or_index: str | int):
2222
>>> bpd.options.display.progress_bar = None
2323
>>> s = bpd.Series(
2424
... [
25-
... {"version": 1, "project": "pandas"},
26-
... {"version": 2, "project": "pandas"},
27-
... {"version": 1, "project": "numpy"},
25+
... {"project": "pandas", "version": 1},
26+
... {"project": "pandas", "version": 2},
27+
... {"project": "numpy", "version": 1},
2828
... ],
2929
... dtype=bpd.ArrowDtype(pa.struct(
30-
... [("version", pa.int64()), ("project", pa.string())]
30+
... [("project", pa.string()), ("version", pa.int64())]
3131
... ))
3232
... )
3333
@@ -41,7 +41,7 @@ def field(self, name_or_index: str | int):
4141
4242
Extract by field index.
4343
44-
>>> s.struct.field(0)
44+
>>> s.struct.field(1)
4545
0 1
4646
1 2
4747
2 1
@@ -68,22 +68,22 @@ def explode(self):
6868
>>> bpd.options.display.progress_bar = None
6969
>>> s = bpd.Series(
7070
... [
71-
... {"version": 1, "project": "pandas"},
72-
... {"version": 2, "project": "pandas"},
73-
... {"version": 1, "project": "numpy"},
71+
... {"project": "pandas", "version": 1},
72+
... {"project": "pandas", "version": 2},
73+
... {"project": "numpy", "version": 1},
7474
... ],
7575
... dtype=bpd.ArrowDtype(pa.struct(
76-
... [("version", pa.int64()), ("project", pa.string())]
76+
... [("project", pa.string()), ("version", pa.int64())]
7777
... ))
7878
... )
7979
8080
Extract all child fields.
8181
8282
>>> s.struct.explode()
83-
version project
84-
0 1 pandas
85-
1 2 pandas
86-
2 1 numpy
83+
project version
84+
0 pandas 1
85+
1 pandas 2
86+
2 numpy 1
8787
<BLANKLINE>
8888
[3 rows x 2 columns]
8989
@@ -113,8 +113,8 @@ def dtypes(self):
113113
... ))
114114
... )
115115
>>> s.struct.dtypes()
116-
version Int64
117116
project string[pyarrow]
117+
version Int64
118118
dtype: object
119119
120120
Returns:
@@ -140,21 +140,21 @@ def explode(self, column, *, separator: str = "."):
140140
>>> countries = bpd.Series(["cn", "es", "us"])
141141
>>> files = bpd.Series(
142142
... [
143-
... {"version": 1, "project": "pandas"},
144-
... {"version": 2, "project": "pandas"},
145-
... {"version": 1, "project": "numpy"},
143+
... {"project": "pandas", "version": 1},
144+
... {"project": "pandas", "version": 2},
145+
... {"project": "numpy", "version": 1},
146146
... ],
147147
... dtype=bpd.ArrowDtype(pa.struct(
148-
... [("version", pa.int64()), ("project", pa.string())]
148+
... [("project", pa.string()), ("version", pa.int64())]
149149
... ))
150150
... )
151151
>>> downloads = bpd.Series([100, 200, 300])
152152
>>> df = bpd.DataFrame({"country": countries, "file": files, "download_count": downloads})
153153
>>> df.struct.explode("file")
154-
country file.version file.project download_count
155-
0 cn 1 pandas 100
156-
1 es 2 pandas 200
157-
2 us 1 numpy 300
154+
country file.project file.version download_count
155+
0 cn pandas 1 100
156+
1 es pandas 2 200
157+
2 us numpy 1 300
158158
<BLANKLINE>
159159
[3 rows x 4 columns]
160160

0 commit comments

Comments
 (0)