@@ -6,6 +6,7 @@
Loading
6 6
from .crypt_helper import encrypt_data, decrypt_data
7 7
from .data1a import marathon, donnees_enquete_2003_television
8 8
from .data2a import wines_quality
9 +
from .data_shape_files import data_shape_files, load_french_departments
9 10
from .data_irep import load_irep
10 11
from .datasql import simple_database
11 12
from .datatext import load_sentiment_dataset

@@ -11,7 +11,7 @@
Loading
11 11
if sys.version_info[0] < 3:
12 12
    raise ImportError("ensae_teaching_cs only works with Python 3")
13 13
14 -
__version__ = "0.9.3050"
14 +
__version__ = "0.9.3061"
15 15
__author__ = "Xavier Dupré"
16 16
__github__ = "https://github.com/sdpython/ensae_teaching_cs"
17 17
__url__ = "http://www.xavierdupre.fr/app/ensae_teaching_cs/helpsphinx/index.html"

@@ -0,0 +1,52 @@
Loading
1 +
# coding: utf-8
2 +
"""
3 +
@file
4 +
@brief Shapefiles data.
5 +
"""
6 +
import os
7 +
import pandas
8 +
from pyquickhelper.filehelper import get_url_content_timeout, unzip_files
9 +
10 +
11 +
def data_shape_files(name, cache=".", load=True):
12 +
    """
13 +
    Downloads shape files.
14 +
15 +
    :param name: name of the shape file (see below)
16 +
    :param cache: cache folder
17 +
    :param load: loads the shape files, the function relies on
18 +
        :epkg:`geopandas`
19 +
    :return: shape files
20 +
21 +
    List of availables shape files:
22 +
    * `'depfr2018'`: see `Contours des départements français issus d'OpenStreetMap
23 +
      <https://www.data.gouv.fr/en/datasets/contours-des-departements-francais-issus-d-openstreetmap/>`_
24 +
    """
25 +
    if name == 'depfr2018':
26 +
        url = 'https://www.data.gouv.fr/en/datasets/r/eb36371a-761d-44a8-93ec-3d728bec17ce'
27 +
        dest = os.path.join(cache, 'departements-20180101-shp.zip')
28 +
        if not os.path.exists(dest):
29 +
            get_url_content_timeout(url, output=dest, encoding=None)
30 +
        res = unzip_files(dest, where_to=cache)
31 +
        shp = [name for name in res if name.endswith('.shp')]
32 +
        if len(shp) == 0:
33 +
            raise FileNotFoundError(  # pragma: no cover
34 +
                "Unable to find shp file in '{}'.".format(cache))
35 +
        import geopandas
36 +
        df = geopandas.read_file(shp[0])
37 +
        df['centroid'] = df['geometry'].apply(lambda r: r.centroid)
38 +
        df['DEPLONG'] = df['centroid'].apply(lambda r: r.x)
39 +
        df['DEPLAT'] = df['centroid'].apply(lambda r: r.y)
40 +
        return df
41 +
    raise ValueError(
42 +
        "Unpexpected value for shape files: '{}'.".format(name))
43 +
44 +
45 +
def load_french_departments():
46 +
    """
47 +
    Loads a dataframe with the list of French
48 +
    departments and the center of each.
49 +
    """
50 +
    this = os.path.abspath(os.path.dirname(__file__))
51 +
    name = os.path.join(this, "data_shp", "departement_french_2018.csv")
52 +
    return pandas.read_csv(name)
Files Coverage
src/ensae_teaching_cs 75.45%
Project Totals (127 files) 75.45%
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading