oprattr 0.3.0__py3-none-any.whl → 0.4.0__py3-none-any.whl

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.

Potentially problematic release.


This version of oprattr might be problematic. Click here for more details.

oprattr/__init__.py CHANGED
@@ -2,11 +2,11 @@ import collections.abc
2
2
  import functools
3
3
  import numbers
4
4
 
5
+ from numerical import operators
5
6
  import numpy
6
7
 
7
8
  from . import abstract
8
9
  from . import mixins
9
- from . import operators
10
10
  from . import typeface
11
11
  from ._operations import (
12
12
  unary,
@@ -121,6 +121,15 @@ class Operand(abstract.Object[T], mixins.Numpy):
121
121
  """Called for numpy.array(self)."""
122
122
  return numpy.array(self._data, *args, **kwargs)
123
123
 
124
+ def _apply_ufunc(self, ufunc, method, *args, **kwargs):
125
+ if ufunc in (numpy.equal, numpy.not_equal):
126
+ # NOTE: We are probably here because the left operand is a
127
+ # `numpy.ndarray`, which would otherwise take control and return the
128
+ # pure `numpy` result.
129
+ f = getattr(ufunc, method)
130
+ return equality(f, *args)
131
+ return super()._apply_ufunc(ufunc, method, *args, **kwargs)
132
+
124
133
 
125
134
  @Operand.implementation(numpy.array_equal)
126
135
  def array_equal(
oprattr/_operations.py CHANGED
@@ -1,4 +1,5 @@
1
- from . import operators
1
+ from numerical import operators
2
+
2
3
  from .abstract import Quantity
3
4
 
4
5
 
@@ -84,19 +85,29 @@ def unary(f: operators.Operator, a):
84
85
 
85
86
  def equality(f: operators.Operator, a, b):
86
87
  """Compute the equality operation f(a, b)."""
88
+ x = a._data if isinstance(a, Quantity) else a
89
+ y = b._data if isinstance(b, Quantity) else b
90
+ fxy = f(x, y)
91
+ try:
92
+ iter(fxy)
93
+ except TypeError:
94
+ r = bool(fxy)
95
+ else:
96
+ r = all(fxy)
97
+ isne = f(1, 2)
87
98
  if isinstance(a, Quantity) and isinstance(b, Quantity):
88
99
  if a._meta != b._meta:
89
- return f is operators.ne
90
- return f(a._data, b._data)
100
+ return isne
101
+ return r
91
102
  if isinstance(a, Quantity):
92
103
  if not a._meta:
93
- return f(a._data, b)
94
- return f is operators.ne
104
+ return r
105
+ return isne
95
106
  if isinstance(b, Quantity):
96
107
  if not b._meta:
97
- return f(a, b._data)
98
- return f is operators.ne
99
- return f(a, b)
108
+ return r
109
+ return isne
110
+ return r
100
111
 
101
112
 
102
113
  def ordering(f: operators.Operator, a, b):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: oprattr
3
- Version: 0.3.0
3
+ Version: 0.4.0
4
4
  Summary: Add your description here
5
5
  Author-email: Matthew Young <myoung.space.science@gmail.com>
6
6
  License-File: LICENSE
@@ -0,0 +1,11 @@
1
+ oprattr/__init__.py,sha256=NPLnNea_NmyxQUX7DLqaC7YB67XATQ2gEhkPmBGpRpo,6044
2
+ oprattr/_operations.py,sha256=UruyOQGERwfiKgJTjJkt_C00BBVFvJMXes2tFxEkXJI,5985
3
+ oprattr/abstract.py,sha256=I3AYc8F79IMgH2esaKSvCTFelV_jFxWRuvXDuTZ8E94,1407
4
+ oprattr/mixins.py,sha256=_qqhReZu9Ta83irVihUrhggcObEj4lyp-3_S9K2hEog,16875
5
+ oprattr/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ oprattr/typeface.py,sha256=FPGAdTZUmS_jd56PcZ5tCcUE_rXNubINBpVMQLRenvg,1214
7
+ oprattr/typeface.pyi,sha256=6gVdlDXtwl6Qyv07JWuRhM78VTGzds0pJ2KZUAAGcXs,113
8
+ oprattr-0.4.0.dist-info/METADATA,sha256=uCu_KrutswZW3e1YyOGuPa_ywL3dO818GJpBmRBFfwI,375
9
+ oprattr-0.4.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
10
+ oprattr-0.4.0.dist-info/licenses/LICENSE,sha256=m2oXG0JDq5RzaKTS57TvGyNq5cWcV4_nfmLZjzLdYTg,1513
11
+ oprattr-0.4.0.dist-info/RECORD,,
oprattr/operators.py DELETED
@@ -1,41 +0,0 @@
1
- """
2
- A namespace for operators used by this package's `Object` class.
3
- """
4
-
5
- import collections.abc
6
- import builtins
7
- import operator
8
-
9
-
10
- class Operator:
11
- """Base class for enhanced operators."""
12
- def __init__(self, __f: collections.abc.Callable, operation: str):
13
- self._f = __f
14
- self._operation = operation
15
-
16
- def __repr__(self):
17
- """Called for repr(self)."""
18
- return self._operation
19
-
20
- def __call__(self, *args, **kwds):
21
- """Called for self(*args, **kwds)."""
22
- return self._f(*args, **kwds)
23
-
24
-
25
- eq = Operator(operator.eq, r'a == b')
26
- ne = Operator(operator.ne, r'a != b')
27
- lt = Operator(operator.lt, r'a < b')
28
- le = Operator(operator.le, r'a <= b')
29
- gt = Operator(operator.gt, r'a > b')
30
- ge = Operator(operator.ge, r'a >= b')
31
- abs = Operator(builtins.abs, r'abs(a)')
32
- pos = Operator(operator.pos, r'+a')
33
- neg = Operator(operator.neg, r'-a')
34
- add = Operator(operator.add, r'a + b')
35
- sub = Operator(operator.sub, r'a - b')
36
- mul = Operator(operator.mul, r'a * b')
37
- truediv = Operator(operator.truediv, r'a / b')
38
- floordiv = Operator(operator.floordiv, r'a // b')
39
- mod = Operator(operator.mod, r'a % b')
40
- pow = Operator(builtins.pow, r'a ** b')
41
-
@@ -1,12 +0,0 @@
1
- oprattr/__init__.py,sha256=eo0zjBDcrDG-Ymeqm-k6lfq18aqCLvgi9ipHNu7wkQg,5591
2
- oprattr/_operations.py,sha256=GwoZjjs-rcX70SuNBAiu-ja9P5dBRAJ0NTfMLQWY6yY,5824
3
- oprattr/abstract.py,sha256=I3AYc8F79IMgH2esaKSvCTFelV_jFxWRuvXDuTZ8E94,1407
4
- oprattr/mixins.py,sha256=_qqhReZu9Ta83irVihUrhggcObEj4lyp-3_S9K2hEog,16875
5
- oprattr/operators.py,sha256=0ix9xHYujJZoUp4mBy1Oar_z17nUlZ8EoKU9KqpaAe0,1172
6
- oprattr/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
- oprattr/typeface.py,sha256=FPGAdTZUmS_jd56PcZ5tCcUE_rXNubINBpVMQLRenvg,1214
8
- oprattr/typeface.pyi,sha256=6gVdlDXtwl6Qyv07JWuRhM78VTGzds0pJ2KZUAAGcXs,113
9
- oprattr-0.3.0.dist-info/METADATA,sha256=a-xInHgyeHOBNhKU1tnnftszWZ8vLumwgeLCYA_Z6-Y,375
10
- oprattr-0.3.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
11
- oprattr-0.3.0.dist-info/licenses/LICENSE,sha256=m2oXG0JDq5RzaKTS57TvGyNq5cWcV4_nfmLZjzLdYTg,1513
12
- oprattr-0.3.0.dist-info/RECORD,,