Skip to content

Commit 5f56ef3

Browse files
committed
fix #688 : fixed small errors in the tutorial_IO notebook
1 parent c2fa6d6 commit 5f56ef3

File tree

2 files changed

+12
-64
lines changed

2 files changed

+12
-64
lines changed

doc/source/tutorial/tutorial_IO.ipyml

Lines changed: 6 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,13 @@ cells:
1313
import warnings
1414
warnings.filterwarnings("ignore", message=r'.*numpy.dtype size changed*')
1515

16-
id: 0
1716
metadata:
1817
nbsphinx: hidden
1918

2019
- code: |
2120
# first of all, import the LArray library
2221
from larray import *
2322

24-
id: 1
2523

2624
- markdown: |
2725
Check the version of LArray:
@@ -31,7 +29,6 @@ cells:
3129
from larray import __version__
3230
__version__
3331

34-
id: 2
3532

3633
- markdown: |
3734
## Loading and Dumping Arrays
@@ -51,7 +48,6 @@ cells:
5148
pop = read_csv(csv_dir + '/pop.csv')
5249
pop
5350

54-
id: 3
5551

5652
- markdown: |
5753
To read an array from a sheet of an Excel file, you can use the ``read_excel`` function:
@@ -65,7 +61,6 @@ cells:
6561
births = read_excel(filepath_excel, 'births')
6662
births
6763

68-
id: 4
6964

7065
- markdown: |
7166
The ``open_excel`` function in combination with the ``load`` method allows you to load several arrays from the same Workbook without opening and closing it several times:
@@ -108,7 +103,6 @@ cells:
108103
deaths = read_hdf(filepath_hdf, 'deaths')
109104
deaths
110105

111-
id: 5
112106

113107
- markdown: |
114108
### Dumping Arrays - Basic Usage (CSV, Excel, HDF5)
@@ -120,7 +114,6 @@ cells:
120114
# save the array pop in the file 'pop.csv'
121115
pop.to_csv('pop.csv')
122116

123-
id: 6
124117

125118
- markdown: |
126119
To write an array to a sheet of an Excel file, you can use the ``to_excel`` method:
@@ -130,7 +123,6 @@ cells:
130123
# save the array pop in the sheet 'pop' of the Excel file 'population.xlsx'
131124
pop.to_excel('population.xlsx', 'pop')
132125

133-
id: 7
134126

135127
- markdown: |
136128
Note that ``to_excel`` create a new Excel file if it does not exist yet.
@@ -141,7 +133,6 @@ cells:
141133
# add a new sheet 'births' to the file 'population.xlsx' and save the array births in it
142134
births.to_excel('population.xlsx', 'births')
143135

144-
id: 8
145136

146137
- markdown: |
147138
To reset an Excel file, you simply need to set the `overwrite_file` argument as True:
@@ -152,7 +143,6 @@ cells:
152143
# 2. create a sheet 'pop' and save the array pop in it
153144
pop.to_excel('population.xlsx', 'pop', overwrite_file=True)
154145

155-
id: 9
156146

157147
- markdown: |
158148
The ``open_excel`` function in combination with the ``dump()`` method allows you to open a Workbook and to export several arrays at once. If the Excel file doesn't exist, the ``overwrite_file`` argument must be set to True.
@@ -180,14 +170,13 @@ cells:
180170

181171

182172
- markdown: |
183-
To write an array in an HDF5 file, you must use the ``read_hdf`` function and provide the key that will be associated with the array:
173+
To write an array in an HDF5 file, you must use the ``to_hdf`` function and provide the key that will be associated with the array:
184174

185175

186176
- code: |
187177
# save the array pop in the file 'population.h5' and associate it with the key 'pop'
188178
pop.to_hdf('population.h5', 'pop')
189179

190-
id: 10
191180

192181
- markdown: |
193182
### Specifying Wide VS Narrow format (CSV, Excel)
@@ -216,14 +205,12 @@ cells:
216205
pop_BE_FR = read_csv(csv_dir + '/pop_narrow_format.csv', wide=False)
217206
pop_BE_FR
218207

219-
id: 11
220208

221209
- code: |
222210
# same for the read_excel function
223211
pop_BE_FR = read_excel(filepath_excel, sheet='pop_narrow_format', wide=False)
224212
pop_BE_FR
225213

226-
id: 12
227214

228215
- markdown: |
229216
By default, writing functions will set the name of the column containing the data to 'value'. You can choose the name of this column by using the ``value_name`` argument. For example, using ``value_name='population'`` you can export the previous array as:
@@ -246,13 +233,11 @@ cells:
246233
# same but replace 'value' by 'population'
247234
pop_BE_FR.to_csv('pop_narrow_format.csv', wide=False, value_name='population')
248235

249-
id: 13
250236

251237
- code: |
252238
# same for the to_excel method
253239
pop_BE_FR.to_excel('population.xlsx', 'pop_narrow_format', wide=False, value_name='population')
254240

255-
id: 14
256241

257242
- markdown: |
258243
Like with the ``to_excel`` method, it is possible to export arrays in a ``narrow`` format using ``open_excel``.
@@ -468,7 +453,6 @@ cells:
468453
# shape and data type of the output array are not what we expected
469454
pop.info
470455

471-
id: 15
472456

473457
- code: |
474458
# by setting the 'nb_axes' argument, you can indicate to read_csv the number of axes of the output array
@@ -480,15 +464,13 @@ cells:
480464
# shape and data type of the output array are what we expected
481465
pop.info
482466

483-
id: 16
484467

485468
- code: |
486469
# same for the read_excel function
487470
pop = read_excel(filepath_excel, sheet='pop_missing_axis_name', nb_axes=3)
488471
pop = pop.rename(-1, 'time')
489472
pop.info
490473

491-
id: 17
492474

493475
- markdown: |
494476
### NaNs and Missing Data Handling at Reading (CSV, Excel)
@@ -511,7 +493,6 @@ cells:
511493
# In that case, the output array is converted to a float array
512494
read_csv(csv_dir + '/pop_missing_values.csv')
513495

514-
id: 18
515496

516497
- markdown: |
517498
However, it is possible to choose which value to use to fill missing cells using the ``fill_value`` argument:
@@ -520,13 +501,11 @@ cells:
520501
- code: |
521502
read_csv(csv_dir + '/pop_missing_values.csv', fill_value=0)
522503

523-
id: 19
524504

525505
- code: |
526506
# same for the read_excel function
527507
read_excel(filepath_excel, sheet='pop_missing_values', fill_value=0)
528508

529-
id: 20
530509

531510
- markdown: |
532511
### Sorting Axes at Reading (CSV, Excel, HDF5)
@@ -538,17 +517,14 @@ cells:
538517
# sort labels at reading --> Male and Female labels are inverted
539518
read_csv(csv_dir + '/pop.csv', sort_rows=True)
540519

541-
id: 21
542520

543521
- code: |
544522
read_excel(filepath_excel, sheet='births', sort_rows=True)
545523

546-
id: 22
547524

548525
- code: |
549526
read_hdf(filepath_hdf, key='deaths', sort_rows=True)
550527

551-
id: 23
552528

553529
- markdown: |
554530
### Metadata (HDF5)
@@ -562,7 +538,6 @@ cells:
562538

563539
pop.info
564540

565-
id: 24
566541

567542
- markdown: |
568543
These metadata are automatically saved and loaded when working with the HDF5 file format:
@@ -574,7 +549,6 @@ cells:
574549
new_pop = read_hdf('population.h5', 'pop')
575550
new_pop.info
576551

577-
id: 25
578552

579553
- markdown: |
580554
<div class="alert alert-warning">
@@ -615,7 +589,6 @@ cells:
615589

616590
print(session.summary())
617591

618-
id: 26
619592

620593
- markdown: |
621594
2) Call the ``load`` method on an existing session and pass the path to the Excel/HDF5 file or to the directory containing CSV files as first argument:
@@ -628,7 +601,6 @@ cells:
628601

629602
print(session.summary())
630603

631-
id: 27
632604

633605
- code: |
634606
# call the load method on the previous session and add the 'births' and 'deaths' arrays to it
@@ -637,7 +609,6 @@ cells:
637609

638610
print(session.summary())
639611

640-
id: 28
641612

642613
- markdown: |
643614
The ``load`` method offers some options:
@@ -653,7 +624,6 @@ cells:
653624

654625
print(session.summary())
655626

656-
id: 29
657627

658628
- markdown: |
659629
2) Setting the ``display`` argument to True, the ``load`` method will print a message each time a new item is loaded:
@@ -666,7 +636,6 @@ cells:
666636
# each time a new item is loaded
667637
session.load(filepath_hdf, display=True)
668638

669-
id: 30
670639

671640
- markdown: |
672641
### Dumping Sessions (CSV, Excel, HDF5)
@@ -688,15 +657,14 @@ cells:
688657
# load session saved in 'population.h5' to see its content
689658
Session('population.h5')
690659

691-
id: 31
692660

693661
- markdown: |
694662
<div class="alert alert-info">
695-
**Note:** Concerning the CSV and Excel formats:
663+
Note: Concerning the CSV and Excel formats:
696664

697-
- all Axis objects are saved together in the same Excel sheet (CSV file) named __axes__(.csv)
698-
- all Group objects are saved together in the same Excel sheet (CSV file) named __groups__(.csv)
699-
- metadata is saved in one Excel sheet (CSV file) named __metadata__(.csv)
665+
- all Axis objects are saved together in the same Excel sheet (CSV file) named `__axes__(.csv)`
666+
- all Group objects are saved together in the same Excel sheet (CSV file) named `__groups__(.csv)`
667+
- metadata is saved in one Excel sheet (CSV file) named `__metadata__(.csv)`
700668

701669
These sheet (CSV file) names cannot be changed.
702670
</div>
@@ -715,7 +683,6 @@ cells:
715683
# load session saved in 'population.h5' to see its content
716684
Session('population.h5')
717685

718-
id: 32
719686

720687
- markdown: |
721688
2) By default, dumping a session to an Excel or HDF5 file will overwrite it. By setting the ``overwrite`` argument to False, you can choose to update the existing Excel or HDF5 file:
@@ -733,7 +700,6 @@ cells:
733700
# load session saved in 'population.h5' to see its content
734701
Session('population.h5')
735702

736-
id: 33
737703

738704
- markdown: |
739705
3) Setting the ``display`` argument to True, the ``save`` method will print a message each time an item is dumped:
@@ -744,7 +710,6 @@ cells:
744710
# each time an item is dumped
745711
session.save('population.h5', display=True)
746712

747-
id: 34
748713

749714
# The lines below here may be deleted if you do not need them.
750715
# ---------------------------------------------------------------------------
@@ -763,27 +728,10 @@ metadata:
763728
name: python
764729
nbconvert_exporter: python
765730
pygments_lexer: ipython3
766-
version: 3.6.4
731+
version: 3.6.8
767732
livereveal:
768733
autolaunch: false
769734
scroll: true
770735
nbformat: 4
771736
nbformat_minor: 2
772737

773-
# ---------------------------------------------------------------------------
774-
data:
775-
[{execution_count: null, outputs: []}, {execution_count: null, outputs: []}, {execution_count: null,
776-
outputs: []}, {execution_count: null, outputs: []}, {execution_count: null, outputs: []},
777-
{execution_count: null, outputs: []}, {execution_count: null, outputs: []}, {execution_count: null,
778-
outputs: []}, {execution_count: null, outputs: []}, {execution_count: null, outputs: []},
779-
{execution_count: null, outputs: []}, {execution_count: null, outputs: []}, {execution_count: null,
780-
outputs: []}, {execution_count: null, outputs: []}, {execution_count: null, outputs: []},
781-
{execution_count: null, outputs: []}, {execution_count: null, outputs: []}, {execution_count: null,
782-
outputs: []}, {execution_count: null, outputs: []}, {execution_count: null, outputs: []},
783-
{execution_count: null, outputs: []}, {execution_count: null, outputs: []}, {execution_count: null,
784-
outputs: []}, {execution_count: null, outputs: []}, {execution_count: null, outputs: []},
785-
{execution_count: null, outputs: []}, {execution_count: null, outputs: []}, {execution_count: null,
786-
outputs: []}, {execution_count: null, outputs: []}, {execution_count: null, outputs: []},
787-
{execution_count: null, outputs: []}, {execution_count: null, outputs: []}, {execution_count: null,
788-
outputs: []}, {execution_count: null, outputs: []}, {execution_count: null, outputs: []}]
789-

doc/source/tutorial/tutorial_IO.ipynb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@
271271
"cell_type": "markdown",
272272
"metadata": {},
273273
"source": [
274-
"To write an array in an HDF5 file, you must use the ``read_hdf`` function and provide the key that will be associated with the array:"
274+
"To write an array in an HDF5 file, you must use the ``to_hdf`` function and provide the key that will be associated with the array:"
275275
]
276276
},
277277
{
@@ -961,11 +961,11 @@
961961
"metadata": {},
962962
"source": [
963963
"<div class=\"alert alert-info\">\n",
964-
" **Note:** Concerning the CSV and Excel formats: \n",
964+
" Note: Concerning the CSV and Excel formats: \n",
965965
" \n",
966-
" - all Axis objects are saved together in the same Excel sheet (CSV file) named __axes__(.csv) \n",
967-
" - all Group objects are saved together in the same Excel sheet (CSV file) named __groups__(.csv) \n",
968-
" - metadata is saved in one Excel sheet (CSV file) named __metadata__(.csv) \n",
966+
" - all Axis objects are saved together in the same Excel sheet (CSV file) named `__axes__(.csv)` \n",
967+
" - all Group objects are saved together in the same Excel sheet (CSV file) named `__groups__(.csv)` \n",
968+
" - metadata is saved in one Excel sheet (CSV file) named `__metadata__(.csv)` \n",
969969
" \n",
970970
" These sheet (CSV file) names cannot be changed. \n",
971971
"</div>"
@@ -1054,7 +1054,7 @@
10541054
"name": "python",
10551055
"nbconvert_exporter": "python",
10561056
"pygments_lexer": "ipython3",
1057-
"version": "3.6.4"
1057+
"version": "3.6.8"
10581058
},
10591059
"livereveal": {
10601060
"autolaunch": false,

0 commit comments

Comments
 (0)