stringcalc 0.1.0.dev16__tar.gz → 0.1.0.dev17__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.
Files changed (33) hide show
  1. stringcalc-0.1.0.dev17/.flake8 +3 -0
  2. {stringcalc-0.1.0.dev16 → stringcalc-0.1.0.dev17}/.pre-commit-config.yaml +5 -5
  3. {stringcalc-0.1.0.dev16 → stringcalc-0.1.0.dev17}/PKG-INFO +1 -1
  4. {stringcalc-0.1.0.dev16 → stringcalc-0.1.0.dev17}/docs/examples/pythagoras-ratios.md +6 -1
  5. {stringcalc-0.1.0.dev16 → stringcalc-0.1.0.dev17}/pyproject.toml +0 -10
  6. {stringcalc-0.1.0.dev16 → stringcalc-0.1.0.dev17}/stringcalc/__init__.py +1 -1
  7. {stringcalc-0.1.0.dev16 → stringcalc-0.1.0.dev17}/stringcalc/frets.py +18 -15
  8. {stringcalc-0.1.0.dev16 → stringcalc-0.1.0.dev17}/stringcalc/tension.py +43 -27
  9. {stringcalc-0.1.0.dev16 → stringcalc-0.1.0.dev17}/tests/test_frets.py +2 -2
  10. {stringcalc-0.1.0.dev16 → stringcalc-0.1.0.dev17}/.readthedocs.yaml +0 -0
  11. {stringcalc-0.1.0.dev16 → stringcalc-0.1.0.dev17}/LICENSE +0 -0
  12. {stringcalc-0.1.0.dev16 → stringcalc-0.1.0.dev17}/README.md +0 -0
  13. {stringcalc-0.1.0.dev16 → stringcalc-0.1.0.dev17}/docs/api.rst +0 -0
  14. {stringcalc-0.1.0.dev16 → stringcalc-0.1.0.dev17}/docs/cli.rst +0 -0
  15. {stringcalc-0.1.0.dev16 → stringcalc-0.1.0.dev17}/docs/cli_gauge-suggest_tb23nw.svg +0 -0
  16. {stringcalc-0.1.0.dev16 → stringcalc-0.1.0.dev17}/docs/cli_gauge-suggest_tb23nw_d.svg +0 -0
  17. {stringcalc-0.1.0.dev16 → stringcalc-0.1.0.dev17}/docs/conf.py +0 -0
  18. {stringcalc-0.1.0.dev16 → stringcalc-0.1.0.dev17}/docs/examples/compare-data.md +0 -0
  19. {stringcalc-0.1.0.dev16 → stringcalc-0.1.0.dev17}/docs/examples/gauge-suggest.md +0 -0
  20. {stringcalc-0.1.0.dev16 → stringcalc-0.1.0.dev17}/docs/examples/tension-plot.md +0 -0
  21. {stringcalc-0.1.0.dev16 → stringcalc-0.1.0.dev17}/docs/index.md +0 -0
  22. {stringcalc-0.1.0.dev16 → stringcalc-0.1.0.dev17}/docs/panel.rst +0 -0
  23. {stringcalc-0.1.0.dev16 → stringcalc-0.1.0.dev17}/docs/prior-art.md +0 -0
  24. {stringcalc-0.1.0.dev16 → stringcalc-0.1.0.dev17}/stringcalc/cli.py +0 -0
  25. {stringcalc-0.1.0.dev16 → stringcalc-0.1.0.dev17}/stringcalc/data/__init__.py +0 -0
  26. {stringcalc-0.1.0.dev16 → stringcalc-0.1.0.dev17}/stringcalc/data/aquila-nng.csv +0 -0
  27. {stringcalc-0.1.0.dev16 → stringcalc-0.1.0.dev17}/stringcalc/data/daddario-tension.csv +0 -0
  28. {stringcalc-0.1.0.dev16 → stringcalc-0.1.0.dev17}/stringcalc/data/ghs.csv +0 -0
  29. {stringcalc-0.1.0.dev16 → stringcalc-0.1.0.dev17}/stringcalc/data/stringjoy.csv +0 -0
  30. {stringcalc-0.1.0.dev16 → stringcalc-0.1.0.dev17}/stringcalc/data/worth.csv +0 -0
  31. {stringcalc-0.1.0.dev16 → stringcalc-0.1.0.dev17}/stringcalc/py.typed +0 -0
  32. {stringcalc-0.1.0.dev16 → stringcalc-0.1.0.dev17}/stringcalc/util.py +0 -0
  33. {stringcalc-0.1.0.dev16 → stringcalc-0.1.0.dev17}/tests/test_string.py +0 -0
@@ -0,0 +1,3 @@
1
+ [flake8]
2
+ max-line-length = 100
3
+ ignore = E203,E402,E501,W503,E226
@@ -8,7 +8,7 @@ repos:
8
8
  - id: check-yaml
9
9
 
10
10
  - repo: https://github.com/asottile/pyupgrade
11
- rev: "v3.19.1"
11
+ rev: "v3.20.0"
12
12
  hooks:
13
13
  - id: pyupgrade
14
14
  args: [--py39-plus]
@@ -23,12 +23,12 @@ repos:
23
23
  hooks:
24
24
  - id: black
25
25
 
26
- - repo: https://github.com/csachs/pyproject-flake8
27
- rev: "v7.0.0"
26
+ - repo: https://github.com/PyCQA/flake8
27
+ rev: "7.3.0"
28
28
  hooks:
29
- - id: pyproject-flake8 # pflake8
29
+ - id: flake8
30
30
 
31
31
  - repo: https://github.com/rbubley/mirrors-prettier
32
- rev: "v3.5.3"
32
+ rev: "v3.6.2"
33
33
  hooks:
34
34
  - id: prettier
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: stringcalc
3
- Version: 0.1.0.dev16
3
+ Version: 0.1.0.dev17
4
4
  Summary: Calculations for instrument strings
5
5
  Author-email: zmoon <zmoon92@gmail.com>
6
6
  Requires-Python: ~=3.9
@@ -16,15 +16,20 @@ from stringcalc.frets import distances
16
16
 
17
17
  I first saw these in [this StackExchange post](https://music.stackexchange.com/questions/93731/does-guitar-fret-spacing-solely-depend-on-the-length-of-the-string).
18
18
  The same diagram can be found [here](https://passyworldofmathematics.com/guitar-mathematics/), which seems to be the original source.
19
+ I used [this table](https://en.wikipedia.org/wiki/Pythagorean_tuning#Method) to fill in (most of) the gaps (leaving out fret 6 since it is ambiguous).
19
20
 
20
21
  ```{code-cell} ipython3
21
22
  # This maps the fret number to the relative distance to the saddle.
22
23
  ratios = {
24
+ 1: "243/256",
23
25
  2: "8/9",
24
- 3: "64/81",
26
+ 3: "27/32",
27
+ 4: "64/81",
25
28
  5: "3/4",
26
29
  7: "2/3",
30
+ 8: "81/128",
27
31
  9: "16/27",
32
+ 10: "9/16",
28
33
  11: "128/243",
29
34
  12: "1/2",
30
35
  }
@@ -56,16 +56,6 @@ exclude = ["data/", ".github/", "panel/", ".gitignore"]
56
56
  [tool.black]
57
57
  line-length = 100
58
58
 
59
- [tool.flake8] # pyproject-flake8
60
- max-line-length = 100
61
- ignore = [
62
- "E203", # whitespace before ':' - doesn't work well with black
63
- "E402", # module level import not at top of file
64
- "E501", # line too long - let black worry about that
65
- "W503", # line break before binary operator
66
- "E226", # missing whitespace around arithmetic operator - not always more readable imho
67
- ]
68
-
69
59
  [tool.isort]
70
60
  profile = "black"
71
61
  line_length = 100
@@ -2,4 +2,4 @@
2
2
  Calculations for instrument strings
3
3
  """
4
4
 
5
- __version__ = "0.1.0.dev16"
5
+ __version__ = "0.1.0.dev17"
@@ -9,14 +9,14 @@ For example:
9
9
 
10
10
  from __future__ import annotations
11
11
 
12
- from typing import Union
12
+ from typing import Final, Union
13
13
 
14
14
  import numpy as np
15
15
  import numpy.typing as npt # v1.21 needed
16
16
  import pandas as pd
17
17
  from pint import Quantity, UnitRegistry
18
18
 
19
- ureg = UnitRegistry()
19
+ ureg: Final[UnitRegistry] = UnitRegistry()
20
20
  # Q_ = ureg.Quantity # mypy doesn't like this one
21
21
 
22
22
  QLike = Union[Quantity, str]
@@ -88,19 +88,22 @@ def distances(N: int, *, L: float, method: str = "et") -> pd.DataFrame:
88
88
  # TODO: comparison to just intonation for specified root
89
89
 
90
90
  df = pd.DataFrame({"n": n, "d": d, "dd": dd, "d_inv": L - d}).set_index("n")
91
- desc = {
92
- "n": "fret number",
93
- "d": "distance from nut to fret",
94
- "dd": "distance from previous fret to current",
95
- "d_inv": "distance from fret to saddle",
96
- }
97
- fancy_col = {
98
- "n": "n",
99
- "d": "d",
100
- "dd": "Δd",
101
- "d_inv": "L−d",
102
- }
103
- df.attrs.update(col_desc=desc, fancy_col=fancy_col)
91
+ df.attrs.update(
92
+ {
93
+ "col_desc": {
94
+ "n": "fret number",
95
+ "d": "distance from nut to fret",
96
+ "dd": "distance from previous fret to current",
97
+ "d_inv": "distance from fret to saddle",
98
+ },
99
+ "fancy_col": {
100
+ "n": "n",
101
+ "d": "d",
102
+ "dd": "Δd",
103
+ "d_inv": "L−d",
104
+ },
105
+ }
106
+ )
104
107
 
105
108
  return df
106
109
 
@@ -13,7 +13,7 @@ import math
13
13
  import re
14
14
  import warnings
15
15
  from functools import lru_cache
16
- from typing import NamedTuple, Protocol
16
+ from typing import NamedTuple, Protocol, cast
17
17
 
18
18
  import pandas as pd
19
19
 
@@ -29,6 +29,15 @@ def _get_data():
29
29
  DATA = _get_data()
30
30
 
31
31
 
32
+ def _assure_string(s: pd.Series) -> pd.Series[str]:
33
+ """For pandas(-stubs), assure type checker that a Series is of string type.
34
+ Really we know that we have pandas string dtype, but pandas-stubs
35
+ doesn't know/care about this yet(?) in terms of concretizing Series.
36
+ """
37
+ assert s.dtype == "string"
38
+ return cast("pd.Series[str]", s)
39
+
40
+
32
41
  @lru_cache(1)
33
42
  def load_data() -> pd.DataFrame:
34
43
  """Load all string data.
@@ -92,9 +101,11 @@ def load_daddario_data(*, for_combined: bool = False) -> pd.DataFrame:
92
101
  if for_combined:
93
102
  df = df.drop(columns=["notes", "tens"])
94
103
 
95
- df["group"] = "D'Addario - " + df["category"] + " - " + df["group"]
96
- df["group_id"] = "DA:" + df["group_id"]
97
- df["id"] = "DA:" + df["id"]
104
+ df["group"] = (
105
+ "D'Addario - " + _assure_string(df["category"]) + " - " + _assure_string(df["group"])
106
+ )
107
+ df["group_id"] = "DA:" + _assure_string(df["group_id"])
108
+ df["id"] = "DA:" + _assure_string(df["id"])
98
109
 
99
110
  df = df.drop(columns=["category", "id_pref", "id_suff"])
100
111
 
@@ -137,12 +148,13 @@ def load_aquila_data(*, nng_density: float = 1300, for_combined: bool = False) -
137
148
  # Set group ID (used to select string type)
138
149
  df["group"] = "New Nylgut"
139
150
  df["group_id"] = "NNG"
151
+ df[["group", "group_id"]] = df[["group", "group_id"]].astype("string")
140
152
 
141
153
  gauge_eqv_cols = [col for col in df.columns if col.startswith("gauge_")]
142
154
  if for_combined:
143
- df["group"] = "Aquila " + df["group"]
144
- df["group_id"] = "A:" + df["group_id"]
145
- df["id"] = "A:" + df["id"]
155
+ df["group"] = "Aquila " + _assure_string(df["group"])
156
+ df["group_id"] = "A:" + _assure_string(df["group_id"])
157
+ df["id"] = "A:" + _assure_string(df["id"])
146
158
 
147
159
  df = df.drop(columns=gauge_eqv_cols)
148
160
  else:
@@ -170,11 +182,12 @@ def load_worth_data(*, for_combined: bool = False) -> pd.DataFrame:
170
182
  # Set group ID (used to select string type)
171
183
  df["group"] = "Fluorocarbon"
172
184
  df["group_id"] = "FC"
185
+ df[["group", "group_id"]] = df[["group", "group_id"]].astype("string")
173
186
 
174
187
  if for_combined:
175
- df["group"] = "Worth " + df["group"]
176
- df["group_id"] = "W" + df["group_id"]
177
- df["id"] = "WFC:" + df["id"]
188
+ df["group"] = "Worth " + _assure_string(df["group"])
189
+ df["group_id"] = "W" + _assure_string(df["group_id"])
190
+ df["id"] = "WFC:" + _assure_string(df["id"])
178
191
 
179
192
  df = df.drop(columns="rho")
180
193
 
@@ -200,9 +213,9 @@ def load_stringjoy_data(*, for_combined: bool = False) -> pd.DataFrame:
200
213
  df = pd.read_csv(DATA.joinpath("stringjoy.csv"), header=0).convert_dtypes()
201
214
 
202
215
  if for_combined:
203
- df["id"] = "SJ:" + df["id"]
204
- df["group"] = "Stringjoy " + df["group"]
205
- df["group_id"] = "SJ:" + df["group_id"]
216
+ df["id"] = "SJ:" + _assure_string(df["id"])
217
+ df["group"] = "Stringjoy " + _assure_string(df["group"])
218
+ df["group_id"] = "SJ:" + _assure_string(df["group_id"])
206
219
 
207
220
  for name in ["group", "group_id"]:
208
221
  df[name] = df[name].astype("category")
@@ -232,9 +245,9 @@ def load_ghs_data(*, for_combined: bool = False) -> pd.DataFrame:
232
245
  df = df.dropna(subset=["gauge"])
233
246
 
234
247
  if for_combined:
235
- df["id"] = "GHS:" + df["id"]
236
- df["group"] = "GHS - " + df["group"]
237
- df["group_id"] = "GHS:" + df["group_id"]
248
+ df["id"] = "GHS:" + _assure_string(df["id"])
249
+ df["group"] = "GHS - " + _assure_string(df["group"])
250
+ df["group_id"] = "GHS:" + _assure_string(df["group_id"])
238
251
 
239
252
  for name in ["group", "group_id"]:
240
253
  df[name] = df[name].astype("category")
@@ -553,16 +566,19 @@ def suggest_gauge(
553
566
  )
554
567
 
555
568
  df = data_sort[["id", "T", "dT"]].sort_values(by="dT").reset_index(drop=True)
556
- desc = {
557
- "id": "Product ID",
558
- "T": "Tension",
559
- "dT": "Tension difference from target tension",
560
- }
561
- fancy_col = {
562
- "id": "ID",
563
- "T": "T",
564
- "dT": "ΔT",
565
- }
566
- df.attrs.update(col_desc=desc, fancy_col=fancy_col)
569
+ df.attrs.update(
570
+ {
571
+ "col_desc": {
572
+ "id": "Product ID",
573
+ "T": "Tension",
574
+ "dT": "Tension difference from target tension",
575
+ },
576
+ "fancy_col": {
577
+ "id": "ID",
578
+ "T": "T",
579
+ "dT": "ΔT",
580
+ },
581
+ }
582
+ )
567
583
 
568
584
  return df
@@ -60,8 +60,8 @@ def test_l_from_d(ab, d, expected):
60
60
  def test_l_from_d_pint():
61
61
  # Seems not to work with `pytest.approx`
62
62
  ret = frets.length_from_distance(ab=(1, 0), d="1in")
63
- expected = 17.817 * frets.ureg["in"]
64
- delta = 5e-4 * frets.ureg["in"]
63
+ expected = 17.817 * frets.ureg("in")
64
+ delta = 5e-4 * frets.ureg("in")
65
65
  assert expected - delta <= ret <= expected + delta
66
66
 
67
67