Skip to content

Commit 9eaa912

Browse files
committed
add read_csv_cached
1 parent b53ebd9 commit 9eaa912

File tree

13 files changed

+100
-49
lines changed

13 files changed

+100
-49
lines changed

_doc/api/tools/index.rst

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,22 @@
1-
21
teachpyx.tools
32
==============
43

5-
64
.. toctree::
75
:maxdepth: 1
86
:caption: submodules
97

10-
118
display/index
129

1310

1411
.. toctree::
1512
:maxdepth: 1
1613
:caption: modules
1714

18-
1915
data_helper
2016
graphviz_helper
2117
helpers
2218
profiling
23-
19+
pandas
2420

2521
.. automodule:: teachpyx.tools
2622
:members:

_doc/api/tools/pandas.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
teachpyx.tools.pandas
3+
=====================
4+
5+
.. automodule:: teachpyx.tools.pandas
6+
:members:
7+
:no-undoc-members:

_doc/articles/2026/2026-03-15-route2026-ml.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ Quelques jeux de données :
2323
<https://visionet.franceagrimer.fr/Pages/SeriesChronologiques.aspx?menuurl=SeriesChronologiques/productions%20vegetales/grandes%20cultures/surfaces,productions,rendements>`_
2424
* `Effectifs d'étudiants inscrits dans les établissements et les formations de l'enseignement supérieur - détail par établissements
2525
<https://www.data.gouv.fr/datasets/effectifs-detudiants-inscrits-dans-les-etablissements-et-les-formations-de-lenseignement-superieur-detail-par-etablissements>`_
26+
* `Résultats du contrôle sanitaire de l'eau distribuée commune par commune
27+
<https://www.data.gouv.fr/datasets/resultats-du-controle-sanitaire-de-leau-distribuee-commune-par-commune>`_
28+
* `Résultats du contrôle sanitaire de l'eau du robinet <https://www.data.gouv.fr/datasets/resultats-du-controle-sanitaire-de-leau-du-robinet>`_
29+
* `Données climatologiques de base - horaires <https://www.data.gouv.fr/datasets/donnees-climatologiques-de-base-horaires>`_
30+
* `Données climatologiques de base - mensuelles <https://www.data.gouv.fr/datasets/donnees-climatologiques-de-base-mensuelles>`_
31+
32+
Fonctions utiles:
33+
34+
* :func:`teachpyx.tools.pandas.read_csv_cached`
2635

2736
Séance 1 (6/2)
2837
==============

_unittests/ut_datasets/test_data_ts.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55

66
class TestDataTs(ExtTestCase):
7-
87
def test_generate_sells(self):
98
df = generate_sells()
109
self.assertEqual(len(df), 731)

_unittests/ut_tools/test_pandas.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import unittest
2+
from teachpyx.ext_test_case import ExtTestCase
3+
from teachpyx.tools.pandas import read_csv_cached
4+
5+
6+
class TestPandas(ExtTestCase):
7+
def test_read_csv_cached(self):
8+
df = read_csv_cached(
9+
"https://github.com/sdpython/teachpyx/raw/main/_data/paris_54000.zip"
10+
)
11+
df2 = read_csv_cached(
12+
"https://github.com/sdpython/teachpyx/raw/main/_data/paris_54000.zip"
13+
)
14+
self.assertEqual(df.shape, df2.shape)
15+
self.assertEqual(list(df.columns), list(df2.columns))
16+
17+
18+
if __name__ == "__main__":
19+
unittest.main()

_unittests/ut_tools/test_profiling.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
"""
2-
@brief test tree node (time=5s)
3-
"""
4-
51
import os
62
import sys
73
import time

teachpyx/tools/data_helper.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ def decompress_zip(filename, dest: str, verbose: bool = False) -> List[str]:
2626
finalfolder = os.path.split(tos)[0]
2727
if not os.path.exists(finalfolder):
2828
if verbose:
29-
print(f"creating folder {finalfolder!r}")
29+
print(f"[decompress_zip] creating folder {finalfolder!r}")
3030
os.makedirs(finalfolder)
3131
if not info.filename.endswith("/"):
3232
with open(tos, "wb") as u:
3333
u.write(data)
3434
files.append(tos)
3535
if verbose:
36-
print(f"unzipped {info.filename!r} to {tos!r}")
36+
print(f"[decompress_zip] unzipped {info.filename!r} to {tos!r}")
3737
elif not tos.endswith("/"):
3838
files.append(tos)
3939
elif not info.filename.endswith("/"):
@@ -45,7 +45,7 @@ def download(
4545
url: str, dest: str = ".", timeout: int = 10, verbose: bool = False
4646
) -> str:
4747
"""
48-
Download one file.
48+
Downloads one file.
4949
5050
:param url: url
5151
:param dest: destination folder
@@ -57,13 +57,13 @@ def download(
5757
dest_zip = os.path.join(dest, filename)
5858
if not os.path.exists(dest_zip):
5959
if verbose:
60-
print(f"downloads into {dest_zip!r} from {url!r}")
60+
print(f"[download] downloads into {dest_zip!r} from {url!r}")
6161
with urlopen(url, timeout=timeout) as u:
6262
content = u.read()
6363
with open(dest_zip, "wb") as f:
6464
f.write(content)
6565
elif verbose:
66-
print(f"already downloaded {dest_zip!r}")
66+
print(f"[download] already downloaded {dest_zip!r}")
6767
return dest_zip
6868

6969

@@ -83,12 +83,12 @@ def download_and_unzip(
8383
dest_zip = os.path.join(dest, filename)
8484
if not os.path.exists(dest_zip):
8585
if verbose:
86-
print(f"downloads into {dest_zip!r} from {url!r}")
86+
print(f"[download_and_unzip] downloads into {dest_zip!r} from {url!r}")
8787
with urlopen(url, timeout=timeout) as u:
8888
content = u.read()
8989
with open(dest_zip, "wb") as f:
9090
f.write(content)
9191
elif verbose:
92-
print(f"already downloaded {dest_zip!r}")
92+
print(f"[download_and_unzip] already downloaded {dest_zip!r}")
9393

9494
return decompress_zip(dest_zip, dest, verbose=verbose)

teachpyx/tools/display/pygame_helper.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,7 @@ def build_diff_image(
304304

305305

306306
def display_line(ligne: List[Tuple[float, float]], screen, pygame):
307-
"""
308-
Affiche une ligne à l'écran.
309-
"""
307+
"""Affiche une ligne à l'écran."""
310308
color = 0, 0, 0
311309
for p in ligne:
312310
pygame.draw.line(screen, color, p, p)

teachpyx/tools/display/video_helper.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,8 @@ def make_video(
4141
By default, the video will have the size of the first image.
4242
It will resize every image to this size before adding them to the video.
4343
"""
44-
if len(images) == 0:
45-
raise ValueError("No image to convert into a video.")
46-
from cv2 import (
47-
VideoWriter,
48-
VideoWriter_fourcc,
49-
imread,
50-
resize,
51-
) # pylint: disable=E0401
44+
assert images == 0, "No image to convert into a video."
45+
from cv2 import VideoWriter, VideoWriter_fourcc, imread, resize
5246

5347
fourcc = VideoWriter_fourcc(*format)
5448
vid = None

teachpyx/tools/graphviz_helper.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,7 @@ def find_graphviz_dot(exc: bool = True) -> str:
5656
return "dot"
5757

5858

59-
def run_subprocess(
60-
args: List[str],
61-
cwd: Optional[str] = None,
62-
):
59+
def run_subprocess(args: List[str], cwd: Optional[str] = None):
6360
assert not isinstance(
6461
args, str
6562
), "args should be a sequence of strings, not a string."
@@ -91,14 +88,14 @@ def run_subprocess(
9188
p.stdout.close()
9289
if raise_exception:
9390
raise RuntimeError(
94-
"An error was found in the output. The build is stopped.\n{output}"
91+
f"An error was found in the output. The build is stopped.\n{output}"
9592
)
9693
return output
9794

9895

9996
def run_graphviz(filename: str, image: str, engine: str = "dot") -> str:
10097
"""
101-
Run :epkg:`Graphviz`.
98+
Runs :epkg:`Graphviz`.
10299
103100
:param filename: filename which contains the graph definition
104101
:param image: output image

0 commit comments

Comments
 (0)