framex 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
framex-0.1.0/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2024 Zafer Kosar
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
framex-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,78 @@
1
+ Metadata-Version: 2.1
2
+ Name: framex
3
+ Version: 0.1.0
4
+ Summary: dataframe operations
5
+ License: MIT
6
+ Author: Zaf4
7
+ Author-email: zafermolbio@gmail.com
8
+ Requires-Python: >=3.11,<4.0
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Requires-Dist: polars (>=1.5.0,<2.0.0)
14
+ Requires-Dist: requests (>=2.32.3,<3.0.0)
15
+ Description-Content-Type: text/markdown
16
+
17
+ # FRAMES
18
+
19
+ Getting __testing datasets__ made easy.
20
+ Built on top of polars.
21
+
22
+ ## Installation
23
+
24
+ to get started, install the library with:
25
+
26
+ ```shell
27
+ pip install framex
28
+ ```
29
+
30
+ ## Usage
31
+
32
+ ```python
33
+ import framex as fx
34
+ ```
35
+
36
+ ### Loading datasets
37
+
38
+ ```python
39
+ iris = fx.load("iris")
40
+ ```
41
+
42
+ which returns a polars __DataFrame__
43
+
44
+ ```python
45
+ iris = fx.load("iris", lazy=True)
46
+ ```
47
+
48
+ which returns a polars __LazyFrame__
49
+
50
+ Both these operations create local copies of the datasets
51
+ as by default ```cahce=True```.
52
+
53
+ ### Available datasets
54
+
55
+ To see the list of available datasets, run:
56
+
57
+ ```python
58
+ fx.available()
59
+ ```
60
+
61
+ ```python
62
+ {'remote': ['iris', 'mpg', 'netflix', 'starbucks', 'titanic'], 'local': ['titanic']}
63
+ ```
64
+
65
+ which returns a dictionary of both __locally__ and __remotely__ available datasets.
66
+
67
+ To see only __local__ or __remote__ datasets, run:
68
+
69
+ ```python
70
+ fx.available("local")
71
+ fx.available("remote")
72
+ ```
73
+
74
+ ```python
75
+ {'local': ['titanic']}
76
+ {'remote': ['iris', 'mpg', 'netflix', 'starbucks', 'titanic']}
77
+ ```
78
+
framex-0.1.0/README.md ADDED
@@ -0,0 +1,61 @@
1
+ # FRAMES
2
+
3
+ Getting __testing datasets__ made easy.
4
+ Built on top of polars.
5
+
6
+ ## Installation
7
+
8
+ to get started, install the library with:
9
+
10
+ ```shell
11
+ pip install framex
12
+ ```
13
+
14
+ ## Usage
15
+
16
+ ```python
17
+ import framex as fx
18
+ ```
19
+
20
+ ### Loading datasets
21
+
22
+ ```python
23
+ iris = fx.load("iris")
24
+ ```
25
+
26
+ which returns a polars __DataFrame__
27
+
28
+ ```python
29
+ iris = fx.load("iris", lazy=True)
30
+ ```
31
+
32
+ which returns a polars __LazyFrame__
33
+
34
+ Both these operations create local copies of the datasets
35
+ as by default ```cahce=True```.
36
+
37
+ ### Available datasets
38
+
39
+ To see the list of available datasets, run:
40
+
41
+ ```python
42
+ fx.available()
43
+ ```
44
+
45
+ ```python
46
+ {'remote': ['iris', 'mpg', 'netflix', 'starbucks', 'titanic'], 'local': ['titanic']}
47
+ ```
48
+
49
+ which returns a dictionary of both __locally__ and __remotely__ available datasets.
50
+
51
+ To see only __local__ or __remote__ datasets, run:
52
+
53
+ ```python
54
+ fx.available("local")
55
+ fx.available("remote")
56
+ ```
57
+
58
+ ```python
59
+ {'local': ['titanic']}
60
+ {'remote': ['iris', 'mpg', 'netflix', 'starbucks', 'titanic']}
61
+ ```
@@ -0,0 +1,3 @@
1
+ from framex.datasets import available, load
2
+
3
+ __all__ = ["available", "load"]
@@ -0,0 +1,14 @@
1
+ from framex._dicts._all import _DATASETS, _REMOTE_DATASETS
2
+ from framex._dicts._constants import _EXTENSION, _LOCAL_DIR, _REMOTE_DIR_GITHUB
3
+ from framex._dicts._github import _GITHUB_DATASETS
4
+ from framex._dicts._local import _LOCAL_CACHES
5
+
6
+ __all__ = [
7
+ "_EXTENSION",
8
+ "_LOCAL_DIR",
9
+ "_REMOTE_DIR_GITHUB",
10
+ "_GITHUB_DATASETS",
11
+ "_LOCAL_CACHES",
12
+ "_DATASETS",
13
+ "_REMOTE_DATASETS",
14
+ ]
@@ -0,0 +1,8 @@
1
+ from framex._dicts._github import _GITHUB_DATASETS
2
+ from framex._dicts._local import _LOCAL_CACHES
3
+
4
+ # more will be added later
5
+
6
+ # merge dictionaries
7
+ _REMOTE_DATASETS = {**_GITHUB_DATASETS}
8
+ _DATASETS = {**_LOCAL_CACHES, **_REMOTE_DATASETS}
@@ -0,0 +1,5 @@
1
+ from pathlib import Path
2
+
3
+ _LOCAL_DIR = Path(__file__).parent.parent / "data"
4
+ _REMOTE_DIR_GITHUB = "https://github.com/Zaf4/datasets/raw/main/feather/"
5
+ _EXTENSION = ".feather"
@@ -0,0 +1,38 @@
1
+ from __future__ import annotations
2
+
3
+ import requests
4
+
5
+ from framex._dicts._constants import _EXTENSION
6
+
7
+ # GitHub API URL for the directory contents
8
+ _API_URL = "https://api.github.com/repos/Zaf4/datasets/contents/feather"
9
+
10
+
11
+ def _get_names(api_url: str) -> dict[str, str]:
12
+ """
13
+ Get the names of the datasets from the GitHub API.
14
+
15
+ Parameters
16
+ ----------
17
+ api_url : str
18
+ The URL of the GitHub API.
19
+
20
+ Returns
21
+ -------
22
+ list of str
23
+ The names of the datasets.
24
+ """
25
+ response = requests.get(api_url)
26
+ files = response.json()
27
+
28
+ # Extract .feather files
29
+ datasets = {
30
+ file["name"].rstrip(_EXTENSION): file["download_url"]
31
+ for file in files
32
+ if file["name"].endswith(_EXTENSION)
33
+ }
34
+
35
+ return datasets
36
+
37
+
38
+ _GITHUB_DATASETS = _get_names(_API_URL)
@@ -0,0 +1,6 @@
1
+ from pathlib import Path
2
+
3
+ from framex._dicts._constants import _EXTENSION, _LOCAL_DIR
4
+
5
+ # find locally cached _EXTENSION files
6
+ _LOCAL_CACHES = {path.stem: path for path in Path(_LOCAL_DIR).glob(f"*{_EXTENSION}")}
@@ -0,0 +1,3 @@
1
+ from framex.datasets._core import available, load
2
+
3
+ __all__ = ["available", "load"]
@@ -0,0 +1,99 @@
1
+ from __future__ import annotations
2
+
3
+ from pathlib import Path
4
+ from typing import TYPE_CHECKING
5
+
6
+ from polars import read_ipc, scan_ipc
7
+
8
+ from framex._dicts import _DATASETS, _LOCAL_CACHES, _REMOTE_DATASETS
9
+ from framex._dicts._constants import _LOCAL_DIR
10
+
11
+ if TYPE_CHECKING:
12
+ from polars import DataFrame, LazyFrame
13
+
14
+
15
+ def load(
16
+ name: str, *, lazy: bool = False, check_local: bool = True, cache: bool = True
17
+ ) -> DataFrame | LazyFrame:
18
+ """
19
+ Loads dataset by with the given name if available.
20
+
21
+ Parameters
22
+ ----------
23
+ name : str
24
+ Name of the dataset to load.
25
+ lazy : bool, optional
26
+ Lazy loading,
27
+ Default is False
28
+
29
+ check_local : bool, optional
30
+ Whether to check if the dataset is available locally
31
+ Default is True
32
+
33
+ cache : bool, optional
34
+ Whether to cache the dataset locally.
35
+ Default is True
36
+
37
+ Returns
38
+ -------
39
+ polars.DataFrame or polars.LazyFrame
40
+ """
41
+ # select the function to load the dataset
42
+ loader = scan_ipc if lazy else read_ipc
43
+ # check if the dataset is available
44
+ if name not in _DATASETS:
45
+ msg = f"Dataset {name} not found."
46
+ raise ValueError(msg)
47
+
48
+ local_path = _LOCAL_CACHES.get(name)
49
+ # load the dataset
50
+ if check_local:
51
+ if Path(local_path).exists():
52
+ frame = loader(local_path)
53
+ else:
54
+ frame = loader(_DATASETS.get(name))
55
+ else:
56
+ frame = loader(_DATASETS.get(name))
57
+
58
+ # cache the dataset locally
59
+ if cache and not Path(local_path).exists():
60
+ if lazy:
61
+ frame.sink_ipc(local_path, compression="zstd")
62
+ else:
63
+ frame.write_ipc(local_path, compression="zstd")
64
+
65
+ return frame
66
+
67
+
68
+ def available(option: str | None = None) -> list[str]:
69
+ """
70
+ List available datasets.
71
+
72
+ Parameters
73
+ ----------
74
+ option : str, optional {"remote", "local"}
75
+ The option to list available datasets.
76
+ Default is None
77
+
78
+ Returns
79
+ -------
80
+ list of available datasets
81
+
82
+ Raises
83
+ ------
84
+ ValueError
85
+ If the option is not 'remote' or 'local'.
86
+
87
+ """
88
+ if option is None:
89
+ return {
90
+ "remote": list(_REMOTE_DATASETS.keys()),
91
+ "local": list(_LOCAL_CACHES.keys()),
92
+ }
93
+ elif option == "remote":
94
+ return {option: list(_REMOTE_DATASETS.keys())}
95
+ elif option == "local":
96
+ return {option: list(_LOCAL_CACHES.keys())}
97
+ else:
98
+ msg = "Invalid option. Please use either 'remote' or 'local'."
99
+ raise ValueError(msg)
@@ -0,0 +1,89 @@
1
+ [tool.poetry]
2
+ name = "framex"
3
+ version = "0.1.0"
4
+ description = "dataframe operations"
5
+ authors = ["Zaf4 <zafermolbio@gmail.com>"]
6
+ license = "MIT"
7
+ readme = "README.md"
8
+
9
+ [tool.poetry.dependencies]
10
+ python = "^3.11"
11
+ polars = "^1.5.0"
12
+ requests = "^2.32.3"
13
+
14
+ [tool.poetry.group.dev.dependencies]
15
+ ruff = "^0.6.1"
16
+ mypy = "^1.11.1"
17
+
18
+ [build-system]
19
+ requires = ["poetry-core"]
20
+ build-backend = "poetry.core.masonry.api"
21
+
22
+ [tool.ruff.lint]
23
+ select = [
24
+ "E", # pycodestyle
25
+ "W", # pycodestyle
26
+ "F", # Pyflakes
27
+ "B", # flake8-bugbear
28
+ "C4", # flake8-comprehensions
29
+ "D", # flake8-docstrings
30
+ "D213", # Augment NumPy docstring convention: Multi-line docstring summary should start at the second line
31
+ "D417", # Augment NumPy docstring convention: Missing argument descriptions
32
+ "I", # isort
33
+ "SIM", # flake8-simplify
34
+ "TCH", # flake8-type-checking
35
+ "TID", # flake8-tidy-imports
36
+ "UP", # pyupgrade
37
+ "PT", # flake8-pytest-style
38
+ "RUF", # Ruff-specific rules
39
+ "PTH", # flake8-use-pathlib
40
+ "FA", # flake8-future-annotations
41
+ "PIE", # flake8-pie
42
+ "TD", # flake8-todos
43
+ "TRY", # tryceratops
44
+ "EM", # flake8-errmsg
45
+ "FBT001", # flake8-boolean-trap
46
+ ]
47
+
48
+ ignore = [
49
+ # Line length regulated by formatter
50
+ "E501",
51
+ # pydocstyle: http://www.pydocstyle.org/en/stable/error_codes.html
52
+ "D401", # Relax NumPy docstring convention: First line should be in imperative mood
53
+ # flake8-pytest-style:
54
+ "PT011", # pytest.raises({exception}) is too broad, set the match parameter or use a more specific exception
55
+ # flake8-simplify
56
+ "SIM102", # Use a single `if` statement instead of nested `if` statements
57
+ "SIM108", # Use ternary operator
58
+ # ruff
59
+ "RUF005", # unpack-instead-of-concatenating-to-collection-literal
60
+ # pycodestyle
61
+ # TODO: Remove errors below to further improve docstring linting
62
+ # Ordered from most common to least common errors.
63
+ "D105", # Missing docstring in magic method
64
+ "D100", # Missing docstring in public module
65
+ "D104", # Missing docstring in public package
66
+ # flake8-todos
67
+ "TD002", # Missing author in TODO
68
+ "TD003", # Missing issue link on the line following this TODO
69
+ # tryceratops
70
+ "TRY003", # Avoid specifying long messages outside the exception class
71
+ # Lints below are turned off because of conflicts with the ruff formatter
72
+ "D206",
73
+ "W191",
74
+ ]
75
+
76
+ [tool.ruff.lint.pycodestyle]
77
+ max-doc-length = 88
78
+
79
+ [tool.ruff.lint.pydocstyle]
80
+ convention = "numpy"
81
+
82
+ [tool.ruff.lint.flake8-tidy-imports]
83
+ ban-relative-imports = "all"
84
+
85
+ [tool.ruff.lint.flake8-type-checking]
86
+ strict = true
87
+
88
+ [tool.ruff.format]
89
+ docstring-code-format = true