Skip to content

Commit 9f19a4d

Browse files
Added github actions
1 parent 19c3f1f commit 9f19a4d

6 files changed

Lines changed: 82 additions & 45 deletions

File tree

.github/workflows/python.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Python Package CI
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
11+
jobs:
12+
build:
13+
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v2
19+
20+
- name: Set up Python
21+
uses: actions/setup-python@v2
22+
with:
23+
python-version: 3.9
24+
25+
- name: Install dependencies
26+
run: |
27+
python -m pip install --upgrade pip
28+
pip install ".[test]"
29+
30+
- name: Run tests
31+
run: |
32+
pytest
33+
34+
- name: Build package
35+
run: |
36+
python -m pip install wheel
37+
python setup.py sdist bdist_wheel

README.rst

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
Transpose Dictionary
99
======================
10-
|pip| |downloads|
10+
|pip| |downloads| |github|
1111

1212
Simple python package to transpose python dictionaries.
1313

@@ -62,6 +62,10 @@ The software is released under the MIT license.
6262
.. |pip| image:: https://badge.fury.io/py/transpose-dict.svg
6363
:target: https://badge.fury.io/py/transpose-dict
6464

65-
.. |downloads| image:: https://pepy.tech/badge/deflate-dict
66-
:target: https://pepy.tech/badge/deflate-dict
67-
:alt: Pypi total project downloads
65+
.. |downloads| image:: https://pepy.tech/badge/transpose-dict
66+
:target: https://pepy.tech/badge/transpose-dict
67+
:alt: Pypi total project downloads
68+
69+
.. |github| image:: https://github.com/LucaCappelletti94/transpose-dict/actions/workflows/python.yml/badge.svg
70+
:target: https://github.com/LucaCappelletti94/dict_hash/actions/
71+
:alt: Github Actions

setup.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1+
"""Setup script for the package."""
12
import os
23
import re
3-
import sys
4-
# To use a consistent encoding
5-
from codecs import open
64
from os import path
75

86
from setuptools import find_packages, setup
@@ -15,7 +13,7 @@
1513

1614

1715
def read(*parts):
18-
with open(os.path.join(here, *parts), 'r') as fp:
16+
with open(os.path.join(here, *parts), 'r', encoding="utf8") as fp:
1917
return fp.read()
2018

2119

@@ -30,7 +28,7 @@ def find_version(*file_paths):
3028

3129
__version__ = find_version("transpose_dict", "__version__.py")
3230

33-
test_deps = ['pytest', 'pytest-cov', 'coveralls']
31+
test_deps = ['pytest', 'pytest-cov']
3432

3533
extras = {
3634
'test': test_deps,

transpose_dict/__init__.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
"""Module providing tools to transpose dictionaries."""
2-
from support_developer import support_luca
3-
from .transpose_dict import transpose_dict
2+
from transpose_dict.transpose_dict import transpose_dict
43

54
# Create an alias in order to make code more compact
65
TD = transpose_dict
76

8-
support_luca("transpose_dict")
9-
107
__all__ = ["transpose_dict", "TD"]

transpose_dict/__version__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
__version__ = "1.1.3"
1+
"""Current version of the transpose-dict package."""
2+
__version__ = "1.1.3"

transpose_dict/transpose_dict.py

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,48 @@
11
"""Module providing tooling to elaborate a dictionary object."""
2+
23
from typing import Dict, Set, Any
34

45

5-
def dict_of_dict(D: Dict) -> bool:
6+
def is_dict_of_dict(dictionary: Dict) -> bool:
67
"""Return whether given dictionary contains only dictionaries.
78
89
Parameters
910
-------------------------------
10-
D: Dict
11+
dictionary: Dict
1112
Dictionary of which to determine if contains only dictionaries.
1213
1314
Returns
1415
-------------------------------
1516
Boolean representing whether given dictionary contains only dictionaries.
1617
"""
17-
return all(isinstance(d, dict) for d in D.values())
18+
return all(isinstance(value, dict) for value in dictionary.values())
1819

1920

20-
def min_depth(D: Dict) -> int:
21+
def min_depth(dictionary: Dict) -> int:
2122
"""Return minimum depth of given dictionary.
2223
2324
Parameters
2425
-------------------------------
25-
D: Dict
26+
dictionary: Dict
2627
Dictionary of which to determine the width
2728
2829
Returns
2930
-------------------------------
3031
Minimum depth of dictionary.
3132
"""
32-
return 1 + min(
33-
min_depth(d) for d in D.values()
34-
) if dict_of_dict(D) else 0
33+
return (
34+
1 + min(min_depth(value) for value in dictionary.values())
35+
if is_dict_of_dict(dictionary)
36+
else 0
37+
)
3538

3639

37-
def axis_keys(D: Dict, axis: int) -> Set[Any]:
40+
def axis_keys(dictionary: Dict, axis: int) -> Set[Any]:
3841
"""Return set of keys at given axis.
3942
4043
Parameters
4144
-------------------------------
42-
D: Dict
45+
dictionary: Dict
4346
Dictionary to determine keys of.
4447
Axis:int
4548
Depth of keys.
@@ -48,17 +51,19 @@ def axis_keys(D: Dict, axis: int) -> Set[Any]:
4851
-------------------------------
4952
The set of keys at given axis
5053
"""
51-
return set.union(*[
52-
axis_keys(d, axis-1) for d in D.values()
53-
]) if axis else set(D.keys())
54+
return (
55+
set.union(*[axis_keys(value, axis - 1) for value in dictionary.values()])
56+
if axis
57+
else set(dictionary.keys())
58+
)
5459

5560

56-
def reindex_key(D: Dict, key: Any, axis: int) -> Dict:
61+
def reindex_key(dictionary: Dict, key: Any, axis: int) -> Dict:
5762
"""Return reindex dictionary to given key.
5863
5964
Parameters
6065
-------------------------------
61-
D: Dict
66+
dictionary: Dict
6267
Dictionary to reindex.
6368
key: Any
6469
Key to reindex.
@@ -70,34 +75,30 @@ def reindex_key(D: Dict, key: Any, axis: int) -> Dict:
7075
Reindexed dictionary.
7176
"""
7277
if axis == 0:
73-
return D.get(key)
78+
return dictionary.get(key)
7479
return {
7580
subkey: value
76-
for subkey, value in
77-
(
81+
for subkey, value in (
7882
(
7983
subkey,
80-
value
81-
if not isinstance(value, dict)
82-
else
83-
reindex_key(
84-
value,
85-
key,
86-
axis-1
87-
)
84+
(
85+
value
86+
if not isinstance(value, dict)
87+
else reindex_key(value, key, axis - 1)
88+
),
8889
)
89-
for subkey, value in D.items()
90+
for subkey, value in dictionary.items()
9091
)
9192
if value is not None and (not isinstance(value, dict) or len(value) != 0)
9293
}
9394

9495

95-
def transpose_dict(D: Dict, axis: int) -> Dict:
96+
def transpose_dict(dictionary: Dict, axis: int) -> Dict:
9697
"""Transpose given dictionary on given axis.
9798
9899
Parameters
99100
-------------------------------
100-
D: Dict
101+
dictionary: Dict
101102
Dictionary to transpose.
102103
axis: int
103104
Axis to traspose.
@@ -107,6 +108,5 @@ def transpose_dict(D: Dict, axis: int) -> Dict:
107108
Transposed dictionary.
108109
"""
109110
return {
110-
key: reindex_key(D, key, axis)
111-
for key in axis_keys(D, axis)
111+
key: reindex_key(dictionary, key, axis) for key in axis_keys(dictionary, axis)
112112
}

0 commit comments

Comments
 (0)