Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,18 @@ jobs:
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

- name: Install
run: python setup.py install
# - name: Install
# run: python setup.py install

- name: Copy license
run: cp LICENSE* ./_doc
- name: Copy changelogs
run: cp CHANGELOGS* ./_doc

- name: Documentation
run: python -m sphinx ./_doc ./dist/html -n -w doc.txt
run: |
export PYTHONPATH=.
python -m sphinx ./_doc ./dist/html -n -w doc.txt

- name: Summary
run: cat doc.txt
Expand Down
1 change: 1 addition & 0 deletions CHANGELOGS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Change Logs
0.4.0
+++++

* :pr:`55`: add one map
* :pr:`54`: add content for machine learning
* :pr:`47`: add helpers to create a video

Expand Down
7 changes: 6 additions & 1 deletion _doc/api/datasets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@
Jeux de données
===============

Cartographie
============

.. autofunction:: teachpyx.datasets.load_enedis_dataset

Classification
==============

.. autofunction:: teachpyx.datasets.wines.load_wines_dataset
.. autofunction:: teachpyx.datasets.load_wines_dataset

Outils
======
Expand Down
1,108 changes: 1,108 additions & 0 deletions _doc/c_data/enedis_cartes.ipynb

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions _doc/c_data/graphes.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
=======
Graphes
=======

.. toctree::
:maxdepth: 2

enedis_cartes
1 change: 1 addition & 0 deletions _doc/c_data/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ pour la manipulations de données avec les *DataFrames*.

matrices
dataframes
graphes
12 changes: 0 additions & 12 deletions _doc/c_data/nb_dataframe.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6168,18 +6168,6 @@
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down
8 changes: 2 additions & 6 deletions _doc/c_ml/rappel.rst
Original file line number Diff line number Diff line change
Expand Up @@ -527,10 +527,8 @@ en :epkg:`R`.
Dessiner des cartes
===================

.. toctree::
:maxdepth: 1
Voir :ref:`Tracer une carte <nbl-c_data-enedis_cartes>`.

notebooks/enedis_cartes

Exercices
=========
Expand All @@ -547,6 +545,4 @@ Si tous ces rappels vous sont connus, vous devriez être prêt
* `Challenges algorithmiques <http://www.xavierdupre.fr/app/ensae_projects/helpsphinx/index.html#challenges>`_

Un dernier lien vers des exercices dont les questions sont plus détaillées et
corrigées :

* `exercices corrigés <http://www.xavierdupre.fr/app/ensae_teaching_cs/helpsphinx/questions/exams_1A.html#seances-notees>`_
corrigées :ref:`l-examens-notes`.
1 change: 1 addition & 0 deletions _doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@
epkg_dictionary.update(
{
"csv": "https://fr.wikipedia.org/wiki/Comma-separated_values",
"Enedis": "https://data.enedis.fr/",
"fonction": "https://fr.wikipedia.org/wiki/Fonction_(math%C3%A9matiques)",
"fonction continue": "https://fr.wikipedia.org/wiki/Continuit%C3%A9_(math%C3%A9matiques)",
"machine learning": "https://en.wikipedia.org/wiki/Machine_learning",
Expand Down
5 changes: 3 additions & 2 deletions _doc/notebook_gallery.rst
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ Data
c_data/nb_dataframe
c_data/nb_numpy
c_data/nb_pandas
c_data/enedis_cartes

Correction d'examens
====================
Expand Down Expand Up @@ -155,5 +156,5 @@ Machine Learning
.. nblinkgallery::
:caption: machine learning

practice/ml/wines_color
practice/ml/wines_reg
practice/ml/winesc_color
practice/ml/winesr_reg
2 changes: 2 additions & 0 deletions _doc/practice/exams.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Exercices minutés
Ces exercices ont été proposés pour examens d'évaluation.
Il est recommandé de savoir les faire en moins de deux heures.

.. _l-examens-notes:

Séances notées
==============

Expand Down
4 changes: 2 additions & 2 deletions _doc/practice/index_ml.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ Machine Learning
:maxdepth: 1
:caption: Régression

ml/wines_reg
ml/winesr_reg

.. toctree::
:maxdepth: 1
:caption: Classification

ml/wines_color
ml/winesc_color
Original file line number Diff line number Diff line change
Expand Up @@ -1254,18 +1254,6 @@
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down
File renamed without changes.
6 changes: 6 additions & 0 deletions _unittests/ut_datasets/test_documentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ def test_documentation_wines(self):
self.assertIn("<nbl-", links[0])
self.assertIn("wines", links[0])

def test_documentation_enedis(self):
links = list_notebooks_rst_links("c_data", "enedis")
self.assertNotEmpty(links)
self.assertIn("<nbl-c_data", links[0])
self.assertIn("enedis", links[0])

def _test_documentation_movie(self):
links = list_notebooks_rst_links("ml", "movielens")
self.assertNotEmpty(links)
Expand Down
13 changes: 13 additions & 0 deletions _unittests/ut_datasets/test_enedis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import unittest
from teachpyx.ext_test_case import ExtTestCase
from teachpyx.datasets import load_enedis_dataset


class TestEnedis(ExtTestCase):
def test_enedis(self):
df = load_enedis_dataset()
self.assertEqual(df.shape, (9719, 26))


if __name__ == "__main__":
unittest.main()
2 changes: 2 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
black
black-nb
blockdiag
cartopy
chardet
cloudpickle
coverage
cytoolz
dbfread
dict2xml
furo
geopandas
ipython
jinja2
jupyter
Expand Down
3 changes: 2 additions & 1 deletion teachpyx/datasets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
# from .carreau import load_carreau_from_zip
# from .dummies import line2d
# from .duration import duration_selling
# from .enedis import load_enedis_dataset
from .enedis import load_enedis_dataset

# from .geojson import get_geojson_countries
# from .graph import create_tiny_graph
# from .movies import load_movielens_dataset
Expand Down
23 changes: 17 additions & 6 deletions teachpyx/datasets/documentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
from typing import List, Optional


def root() -> str:
def root(subfolder: str) -> str:
"Returns the local folder for all notebooks."
this = os.path.dirname(__file__)
if subfolder == "c_data":
return os.path.abspath(os.path.normpath(os.path.join(this, "..", "..", "_doc")))
return os.path.abspath(
os.path.normpath(os.path.join(this, "..", "..", "_doc", "practice"))
)
Expand All @@ -23,7 +25,7 @@ def list_notebooks(
:param contains: extrait à chercher
:return: liste des notebooks (sans répertoire)
"""
nbs = [os.path.join(root(), subfolder)]
nbs = [os.path.join(root(subfolder), subfolder)]
nb_ = list(filter(os.path.exists, nbs))
assert len(nb_) > 0, "Unable to find notebooks in\n{0}".format("\n".join(nbs))
nb = nb_[0]
Expand All @@ -33,7 +35,12 @@ def list_notebooks(
names = [_ for _ in os.listdir(nb) if _.startswith(name_)]
if contains is not None:
names = [_ for _ in os.listdir(nb) if contains in _]
assert len(names) > 0, f"Unable to find any notebook in '{nb}'."
assert len(names) > 0, (
f"Unable to find any notebook in {nb!r} "
f"(this file is {__file__}, "
f"root is {root(subfolder)}, "
f"sub is {subfolder!r}, name is {name!r})."
)
return names


Expand All @@ -54,8 +61,11 @@ def _name(s):

def _title(sub, s):
reg = re.compile("# (.+)")
fn = os.path.join(root(), sub, s)
assert os.path.exists(fn), f"Unable to find filename {fn!r}."
fn = os.path.join(root(sub), sub, s)
assert os.path.exists(fn), (
f"Unable to find filename {fn!r} (this file is {__file__}, "
f"root is {root(sub)!r}, sub is {sub!r}, name is {name!r})."
)
with open(fn, "r", encoding="utf-8") as f:
content = f.read()
f = reg.findall(content)
Expand All @@ -64,7 +74,8 @@ def _title(sub, s):
return title

names = list_notebooks(subfolder, name, contains)
prefix = "" if subfolder == "c_data" else "practice-"
return [
f":ref:`{_title(subfolder, name)} <nbl-practice-{subfolder}-{_name(name)}>`"
f":ref:`{_title(subfolder, name)} <nbl-{prefix}{subfolder}-{_name(name)}>`"
for name in names
]
30 changes: 30 additions & 0 deletions teachpyx/datasets/enedis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# coding: utf-8
import pandas


def load_enedis_dataset() -> pandas.DataFrame:
"""
Retourne des données extraites du site :epkg:`Enedis` :
`Production électrique annuelle par filière à la maille commune
<https://data.enedis.fr/explore/dataset/production-electrique-par-filiere-a-la-maille-commune/export/>`_.
Le jeu proposé est un extrait pour les années 2015-2016.
Notebooks associés à ce jeu de données :

.. runpython::
:rst:

from teachpyx.datasets.documentation import list_notebooks_rst_links
links = list_notebooks_rst_links("c_data", "enedis")
links = [" * %s" % s for s in links]
print("\\n".join(links))

:return: :epkg:`pandas:DataFrame`
"""
url = (
"https://github.com/sdpython/teachdata/raw/main/enedis/"
"production-electrique-par-filiere-a-la-maille-commune.extrait.2015-2016.csv.zip"
)
df = pandas.read_csv(url, sep=";", encoding="utf-8")
df["long"] = df["Geo Point 2D"].apply(lambda x: float(x.split(",")[1].strip()))
df["lat"] = df["Geo Point 2D"].apply(lambda x: float(x.split(",")[0].strip()))
return df
10 changes: 5 additions & 5 deletions teachpyx/datasets/wines.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import pandas
from numpy.random import permutation
import pandas
from .data_helper import get_data_folder


Expand All @@ -19,7 +19,7 @@ def load_wines_dataset(
:rst:

from teachpyx.datasets.documentation import list_notebooks_rst_links
links = list_notebooks_rst_links("ml", "wines")
links = list_notebooks_rst_links("ml", "winesr")
links = [" * %s" % s for s in links]
print("\\n".join(links))

Expand Down Expand Up @@ -58,14 +58,14 @@ def load_wine_dataset(
.. runpython::
:rst:

from papierstat.datasets.documentation import list_notebooks_rst_links
links = list_notebooks_rst_links("ml", "linreg")
from teachpyx.datasets.documentation import list_notebooks_rst_links
links = list_notebooks_rst_links("ml", "winesc")
links = [" * %s" % s for s in links]
print("\\n".join(links))

:param download: télécharge le jeu de données ou considères une copie en local.
:param shuffle: permute aléatoire les données (elles ne le sont pas)
:return: :class:`pandas:DataFrame`
:return: :class:`pandas.DataFrame`
"""
if download:
url = "https://archive.ics.uci.edu/ml/machine-learning-databases/wine/wine.data"
Expand Down