Skip to content

Commit fe86639

Browse files
committed
improve type folding
1 parent f81e3de commit fe86639

File tree

12 files changed

+150
-24
lines changed

12 files changed

+150
-24
lines changed

build/lib/data_algebra/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"""
55

66
__docformat__ = "restructuredtext"
7-
__version__ = "0.9.2"
7+
__version__ = "1.0.0"
88

99
__doc__ = """
1010
`data_algebra`<https://github.com/WinVector/data_algebra> is a piped data wrangling system

build/lib/data_algebra/util.py

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,59 @@ def table_is_keyed_by_columns(table, column_names: Iterable[str]) -> bool:
6262
return max(counts) <= 1
6363

6464

65-
type_conversions = {
65+
# noinspection PyBroadException
66+
def _mk_type_coversion_table():
67+
type_conversions = dict()
6668
# DeprecationWarning: `np.bool` is a deprecated alias for the builtin `bool`.
6769
# To silence this warning, use `bool` by itself. Doing this will not modify any behavior and is safe.
6870
# If you specifically wanted the numpy scalar type, use `np.bool_` here.
6971
# Deprecated in NumPy 1.20; for more details and guidance:
7072
# https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
7173
# (note even numpy.bool_ triggers the above, or the triggering it is in pyspark right now
72-
numpy.bool_: bool,
73-
numpy.int64: int,
74-
numpy.float64: float,
75-
}
74+
try:
75+
type_conversions[numpy.bool_] = bool
76+
except Exception:
77+
pass
78+
try:
79+
type_conversions[numpy.bool] = bool
80+
except Exception:
81+
pass
82+
try:
83+
type_conversions[numpy.int] = int
84+
except Exception:
85+
pass
86+
try:
87+
type_conversions[numpy.int_] = int
88+
except Exception:
89+
pass
90+
try:
91+
type_conversions[numpy.int64] = int
92+
except Exception:
93+
pass
94+
try:
95+
type_conversions[numpy.float64] = float
96+
except Exception:
97+
pass
98+
try:
99+
type_conversions[numpy.float] = float
100+
except Exception:
101+
pass
102+
try:
103+
type_conversions[numpy.float_] = float
104+
except Exception:
105+
pass
106+
try:
107+
type_conversions[numpy.str] = str
108+
except Exception:
109+
pass
110+
try:
111+
type_conversions[numpy.str_] = str
112+
except Exception:
113+
pass
114+
return type_conversions
115+
116+
117+
type_conversions = _mk_type_coversion_table()
76118

77119

78120
def map_type_to_canonical(v: type) -> type:

coverage.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ data_algebra/pandas_model.py 5 0 100%
125125
data_algebra/parse_by_lark.py 143 25 83%
126126
data_algebra/python3_lark.py 1 0 100%
127127
data_algebra/test_util.py 215 42 80%
128-
data_algebra/util.py 94 6 94%
128+
data_algebra/util.py 137 26 81%
129129
----------------------------------------------------------
130-
TOTAL 4978 869 83%
130+
TOTAL 5021 889 82%
131131

132132

133-
============================= 231 passed in 22.32s =============================
133+
============================= 231 passed in 21.81s =============================

data_algebra.egg-info/PKG-INFO

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Metadata-Version: 2.1
22
Name: data-algebra
3-
Version: 0.9.2
3+
Version: 1.0.0
44
Summary: data_algebra is a data manipulation language that can both generate SQL queries and work on Pandas DataFrames.
55
Home-page: https://github.com/WinVector/data_algebra
66
Author: John Mount

data_algebra/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"""
55

66
__docformat__ = "restructuredtext"
7-
__version__ = "0.9.2"
7+
__version__ = "1.0.0"
88

99
__doc__ = """
1010
`data_algebra`<https://github.com/WinVector/data_algebra> is a piped data wrangling system

data_algebra/util.py

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,59 @@ def table_is_keyed_by_columns(table, column_names: Iterable[str]) -> bool:
6262
return max(counts) <= 1
6363

6464

65-
type_conversions = {
65+
# noinspection PyBroadException
66+
def _mk_type_coversion_table():
67+
type_conversions = dict()
6668
# DeprecationWarning: `np.bool` is a deprecated alias for the builtin `bool`.
6769
# To silence this warning, use `bool` by itself. Doing this will not modify any behavior and is safe.
6870
# If you specifically wanted the numpy scalar type, use `np.bool_` here.
6971
# Deprecated in NumPy 1.20; for more details and guidance:
7072
# https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
7173
# (note even numpy.bool_ triggers the above, or the triggering it is in pyspark right now
72-
numpy.bool_: bool,
73-
numpy.int64: int,
74-
numpy.float64: float,
75-
}
74+
try:
75+
type_conversions[numpy.bool_] = bool
76+
except Exception:
77+
pass
78+
try:
79+
type_conversions[numpy.bool] = bool
80+
except Exception:
81+
pass
82+
try:
83+
type_conversions[numpy.int] = int
84+
except Exception:
85+
pass
86+
try:
87+
type_conversions[numpy.int_] = int
88+
except Exception:
89+
pass
90+
try:
91+
type_conversions[numpy.int64] = int
92+
except Exception:
93+
pass
94+
try:
95+
type_conversions[numpy.float64] = float
96+
except Exception:
97+
pass
98+
try:
99+
type_conversions[numpy.float] = float
100+
except Exception:
101+
pass
102+
try:
103+
type_conversions[numpy.float_] = float
104+
except Exception:
105+
pass
106+
try:
107+
type_conversions[numpy.str] = str
108+
except Exception:
109+
pass
110+
try:
111+
type_conversions[numpy.str_] = str
112+
except Exception:
113+
pass
114+
return type_conversions
115+
116+
117+
type_conversions = _mk_type_coversion_table()
76118

77119

78120
def map_type_to_canonical(v: type) -> type:

dist/data_algebra-0.9.2.tar.gz

-74.7 KB
Binary file not shown.

dist/data_algebra-1.0.0.tar.gz

74.8 KB
Binary file not shown.

docs/data_algebra.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ <h1 class="modulename">
9999
<span class="sd">&quot;&quot;&quot;</span>
100100

101101
<span class="n">__docformat__</span> <span class="o">=</span> <span class="s2">&quot;restructuredtext&quot;</span>
102-
<span class="n">__version__</span> <span class="o">=</span> <span class="s2">&quot;0.9.2&quot;</span>
102+
<span class="n">__version__</span> <span class="o">=</span> <span class="s2">&quot;1.0.0&quot;</span>
103103

104104
<span class="vm">__doc__</span> <span class="o">=</span> <span class="s2">&quot;&quot;&quot;</span>
105105
<span class="s2">`data_algebra`&lt;https://github.com/WinVector/data_algebra&gt; is a piped data wrangling system</span>
@@ -136,7 +136,7 @@ <h1 class="modulename">
136136
<span class="sd">&quot;&quot;&quot;</span>
137137

138138
<span class="n">__docformat__</span> <span class="o">=</span> <span class="s2">&quot;restructuredtext&quot;</span>
139-
<span class="n">__version__</span> <span class="o">=</span> <span class="s2">&quot;0.9.2&quot;</span>
139+
<span class="n">__version__</span> <span class="o">=</span> <span class="s2">&quot;1.0.0&quot;</span>
140140

141141
<span class="vm">__doc__</span> <span class="o">=</span> <span class="s2">&quot;&quot;&quot;</span>
142142
<span class="s2">`data_algebra`&lt;https://github.com/WinVector/data_algebra&gt; is a piped data wrangling system</span>

0 commit comments

Comments
 (0)