UnitValues 0.1.1__tar.gz → 0.1.2__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.
- {unitvalues-0.1.1/src/UnitValues.egg-info → unitvalues-0.1.2}/PKG-INFO +5 -4
- {unitvalues-0.1.1 → unitvalues-0.1.2}/README.md +2 -2
- {unitvalues-0.1.1 → unitvalues-0.1.2}/pyproject.toml +7 -3
- {unitvalues-0.1.1 → unitvalues-0.1.2/src/UnitValues.egg-info}/PKG-INFO +5 -4
- {unitvalues-0.1.1 → unitvalues-0.1.2}/src/UnitValues.egg-info/SOURCES.txt +1 -0
- unitvalues-0.1.2/src/UnitValues.egg-info/requires.txt +1 -0
- {unitvalues-0.1.1 → unitvalues-0.1.2}/src/unitvalue/units.py +88 -24
- {unitvalues-0.1.1 → unitvalues-0.1.2}/LICENSE +0 -0
- {unitvalues-0.1.1 → unitvalues-0.1.2}/setup.cfg +0 -0
- {unitvalues-0.1.1 → unitvalues-0.1.2}/src/UnitValues.egg-info/dependency_links.txt +0 -0
- {unitvalues-0.1.1 → unitvalues-0.1.2}/src/UnitValues.egg-info/top_level.txt +0 -0
- {unitvalues-0.1.1 → unitvalues-0.1.2}/src/unitvalue/__init__.py +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: UnitValues
|
|
3
|
-
Version: 0.1.
|
|
4
|
-
Summary: A small package for using units in Python. Allows for computation with dimensioned qauntities and allows you to convert between different units. Do anything you would do with regular floats or integers in Python except now with units. I think you'll find this implementation more elegant then most other unit packages.
|
|
3
|
+
Version: 0.1.2
|
|
4
|
+
Summary: A small package for using units in Python. Allows for computation with dimensioned qauntities and allows you to convert between different units. Do anything you would do with regular floats or integers in Python except now with units. Package is compatible with NumPy, SciPy + Pandas are in the works. I think you'll find this implementation more elegant then most other unit packages.
|
|
5
5
|
Author-email: Brody Howard <brody.howard@mail.utoronto.ca>
|
|
6
6
|
Project-URL: Homepage, https://github.com/BroRocket/unitvalue/
|
|
7
7
|
Project-URL: Issues, https://github.com/BroRocket/unitvalue/issues
|
|
@@ -11,10 +11,11 @@ Classifier: Operating System :: OS Independent
|
|
|
11
11
|
Requires-Python: >=3.8
|
|
12
12
|
Description-Content-Type: text/markdown
|
|
13
13
|
License-File: LICENSE
|
|
14
|
+
Requires-Dist: numpy>=1.23.2
|
|
14
15
|
|
|
15
|
-
#
|
|
16
|
+
# UnitValues Package
|
|
16
17
|
## Introduction
|
|
17
|
-
The UnitValue package is designed to allow easy manipulation and conversion of numerical values associated with units. It currently supports both Imperial and Metric systems and includes commonly used units, with the flexibility to add more units as needed. It works with numpy as well.
|
|
18
|
+
The UnitValue package is designed to allow easy manipulation and conversion of numerical values associated with units. It currently supports both Imperial and Metric systems and includes commonly used units, with the flexibility to add more units as needed. It works with numpy as well, empowering you to use units in your numpy arrays and funciton calls.
|
|
18
19
|
|
|
19
20
|
This package is ideal for applications that require precise unit conversions and tracking of units alongside numerical values.
|
|
20
21
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
#
|
|
1
|
+
# UnitValues Package
|
|
2
2
|
## Introduction
|
|
3
|
-
The UnitValue package is designed to allow easy manipulation and conversion of numerical values associated with units. It currently supports both Imperial and Metric systems and includes commonly used units, with the flexibility to add more units as needed. It works with numpy as well.
|
|
3
|
+
The UnitValue package is designed to allow easy manipulation and conversion of numerical values associated with units. It currently supports both Imperial and Metric systems and includes commonly used units, with the flexibility to add more units as needed. It works with numpy as well, empowering you to use units in your numpy arrays and funciton calls.
|
|
4
4
|
|
|
5
5
|
This package is ideal for applications that require precise unit conversions and tracking of units alongside numerical values.
|
|
6
6
|
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "UnitValues"
|
|
3
|
-
version = "0.1.
|
|
3
|
+
version = "0.1.2"
|
|
4
|
+
dependencies = [
|
|
5
|
+
"numpy>=1.23.2"
|
|
6
|
+
]
|
|
7
|
+
requires-python = ">=3.8"
|
|
4
8
|
authors = [
|
|
5
9
|
{ name="Brody Howard", email="brody.howard@mail.utoronto.ca" },
|
|
6
10
|
]
|
|
7
|
-
description = "A small package for using units in Python. Allows for computation with dimensioned qauntities and allows you to convert between different units. Do anything you would do with regular floats or integers in Python except now with units. I think you'll find this implementation more elegant then most other unit packages."
|
|
11
|
+
description = "A small package for using units in Python. Allows for computation with dimensioned qauntities and allows you to convert between different units. Do anything you would do with regular floats or integers in Python except now with units. Package is compatible with NumPy, SciPy + Pandas are in the works. I think you'll find this implementation more elegant then most other unit packages."
|
|
8
12
|
readme = "README.md"
|
|
9
|
-
|
|
13
|
+
|
|
10
14
|
classifiers = [
|
|
11
15
|
"Programming Language :: Python :: 3",
|
|
12
16
|
"License :: OSI Approved :: MIT License",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: UnitValues
|
|
3
|
-
Version: 0.1.
|
|
4
|
-
Summary: A small package for using units in Python. Allows for computation with dimensioned qauntities and allows you to convert between different units. Do anything you would do with regular floats or integers in Python except now with units. I think you'll find this implementation more elegant then most other unit packages.
|
|
3
|
+
Version: 0.1.2
|
|
4
|
+
Summary: A small package for using units in Python. Allows for computation with dimensioned qauntities and allows you to convert between different units. Do anything you would do with regular floats or integers in Python except now with units. Package is compatible with NumPy, SciPy + Pandas are in the works. I think you'll find this implementation more elegant then most other unit packages.
|
|
5
5
|
Author-email: Brody Howard <brody.howard@mail.utoronto.ca>
|
|
6
6
|
Project-URL: Homepage, https://github.com/BroRocket/unitvalue/
|
|
7
7
|
Project-URL: Issues, https://github.com/BroRocket/unitvalue/issues
|
|
@@ -11,10 +11,11 @@ Classifier: Operating System :: OS Independent
|
|
|
11
11
|
Requires-Python: >=3.8
|
|
12
12
|
Description-Content-Type: text/markdown
|
|
13
13
|
License-File: LICENSE
|
|
14
|
+
Requires-Dist: numpy>=1.23.2
|
|
14
15
|
|
|
15
|
-
#
|
|
16
|
+
# UnitValues Package
|
|
16
17
|
## Introduction
|
|
17
|
-
The UnitValue package is designed to allow easy manipulation and conversion of numerical values associated with units. It currently supports both Imperial and Metric systems and includes commonly used units, with the flexibility to add more units as needed. It works with numpy as well.
|
|
18
|
+
The UnitValue package is designed to allow easy manipulation and conversion of numerical values associated with units. It currently supports both Imperial and Metric systems and includes commonly used units, with the flexibility to add more units as needed. It works with numpy as well, empowering you to use units in your numpy arrays and funciton calls.
|
|
18
19
|
|
|
19
20
|
This package is ideal for applications that require precise unit conversions and tracking of units alongside numerical values.
|
|
20
21
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
numpy>=1.23.2
|
|
@@ -323,10 +323,13 @@ class UnitValue:
|
|
|
323
323
|
return self.value * m.value
|
|
324
324
|
|
|
325
325
|
return UnitValue(None, None, new_unit, self.value * m.value)
|
|
326
|
-
elif isinstance(m, (int, float
|
|
326
|
+
elif isinstance(m, (int, float)):
|
|
327
327
|
return UnitValue(self.__system, self.__dimension, self.__unit, self.value * m)
|
|
328
328
|
else:
|
|
329
|
-
|
|
329
|
+
try:
|
|
330
|
+
return self * float(m) # checking if whatever the type is if it can be converted to float and then used
|
|
331
|
+
except:
|
|
332
|
+
return NotImplemented
|
|
330
333
|
|
|
331
334
|
def __rmul__(self, m) -> 'UnitValue':
|
|
332
335
|
return self.__mul__(m)
|
|
@@ -365,10 +368,13 @@ class UnitValue:
|
|
|
365
368
|
return self.value / d.value
|
|
366
369
|
|
|
367
370
|
return UnitValue(None, None, new_unit, self.value / d.value)
|
|
368
|
-
elif isinstance(d, (int, float
|
|
371
|
+
elif isinstance(d, (int, float)):
|
|
369
372
|
return UnitValue(self.__system, self.__dimension, self.__unit, self.value / d)
|
|
370
373
|
else:
|
|
371
|
-
|
|
374
|
+
try:
|
|
375
|
+
return self / float(d)
|
|
376
|
+
except:
|
|
377
|
+
return NotImplemented
|
|
372
378
|
|
|
373
379
|
def __rtruediv__(self, d) -> 'UnitValue':
|
|
374
380
|
"""
|
|
@@ -404,7 +410,7 @@ class UnitValue:
|
|
|
404
410
|
return d.value / self.value
|
|
405
411
|
|
|
406
412
|
return UnitValue(None, None, new_unit, d.value / self.value)
|
|
407
|
-
elif isinstance(d, (int, float
|
|
413
|
+
elif isinstance(d, (int, float)):
|
|
408
414
|
|
|
409
415
|
units = {}
|
|
410
416
|
self.__process_unit(self.__unit, units, -1)
|
|
@@ -429,7 +435,10 @@ class UnitValue:
|
|
|
429
435
|
new_unit = numer + denom
|
|
430
436
|
return UnitValue(None, None, new_unit, d / self.value)
|
|
431
437
|
else:
|
|
432
|
-
|
|
438
|
+
try:
|
|
439
|
+
return float(d) / self
|
|
440
|
+
except:
|
|
441
|
+
return NotImplemented
|
|
433
442
|
|
|
434
443
|
def __pow__(self, p) -> 'UnitValue':
|
|
435
444
|
"""
|
|
@@ -466,7 +475,10 @@ class UnitValue:
|
|
|
466
475
|
return UnitValue(None, None, new_unit, self.value ** p)
|
|
467
476
|
|
|
468
477
|
else:
|
|
469
|
-
|
|
478
|
+
try:
|
|
479
|
+
return self ** float(p)
|
|
480
|
+
except:
|
|
481
|
+
return NotImplemented
|
|
470
482
|
|
|
471
483
|
def __add__(self, a) -> 'UnitValue':
|
|
472
484
|
"""
|
|
@@ -480,11 +492,14 @@ class UnitValue:
|
|
|
480
492
|
self.convert_base_metric()
|
|
481
493
|
a.convert_base_metric()
|
|
482
494
|
return UnitValue(self.__system, self.__dimension, self.__unit, self.value + a.value)
|
|
483
|
-
|
|
484
|
-
|
|
495
|
+
elif isinstance(a, (int, float)):
|
|
496
|
+
warnings.warn("Adding unitless value to quantity with units")
|
|
485
497
|
return UnitValue(self.__system, self.__dimension, self.__unit, self.value + a)
|
|
486
498
|
else:
|
|
487
|
-
|
|
499
|
+
try:
|
|
500
|
+
return self + float(a)
|
|
501
|
+
except:
|
|
502
|
+
return NotImplemented
|
|
488
503
|
|
|
489
504
|
def __radd__(self, a) -> 'UnitValue':
|
|
490
505
|
return self.__add__(a)
|
|
@@ -501,16 +516,36 @@ class UnitValue:
|
|
|
501
516
|
self.convert_base_metric()
|
|
502
517
|
s.convert_base_metric()
|
|
503
518
|
return UnitValue(self.__system, self.__dimension, self.__unit, self.value - s.value)
|
|
504
|
-
elif isinstance(s, (int, float
|
|
519
|
+
elif isinstance(s, (int, float)):
|
|
520
|
+
warnings.warn("Subtracting unitless value to quantity with units")
|
|
505
521
|
return UnitValue(self.__system, self.__dimension, self.__unit, self.value - s)
|
|
506
|
-
else:
|
|
507
|
-
|
|
522
|
+
else:
|
|
523
|
+
try:
|
|
524
|
+
return self - float(s)
|
|
525
|
+
except:
|
|
526
|
+
return NotImplemented
|
|
508
527
|
|
|
509
528
|
def __rsub__(self, s) -> 'UnitValue':
|
|
510
529
|
return -self.__sub__(s)
|
|
511
530
|
|
|
512
531
|
def __neg__(self):
|
|
513
532
|
return UnitValue(self.__system, self.__dimension, self.__unit, -self.value)
|
|
533
|
+
|
|
534
|
+
def __mod__(self, other) -> int:
|
|
535
|
+
if isinstance(other, UnitValue):
|
|
536
|
+
return self.value % other.value
|
|
537
|
+
elif isinstance(other, (int, float)):
|
|
538
|
+
return self.value % other
|
|
539
|
+
else:
|
|
540
|
+
return NotImplemented
|
|
541
|
+
|
|
542
|
+
def __rmod__(self, other) -> int:
|
|
543
|
+
if isinstance(other, UnitValue):
|
|
544
|
+
return other.value % self.value
|
|
545
|
+
elif isinstance(other, (int, float)):
|
|
546
|
+
return other % self.value
|
|
547
|
+
else:
|
|
548
|
+
return NotImplemented
|
|
514
549
|
|
|
515
550
|
def __abs__(self):
|
|
516
551
|
"""
|
|
@@ -599,17 +634,47 @@ class UnitValue:
|
|
|
599
634
|
Handle NumPy ufunc (universal function) operations for UnitValue objects.
|
|
600
635
|
"""
|
|
601
636
|
out = kwargs.get('out', ())
|
|
602
|
-
inputs = [i.value if isinstance(i, UnitValue) else i for i in inputs]
|
|
603
|
-
|
|
604
|
-
result = getattr(ufunc, method)(*inputs, **kwargs)
|
|
605
637
|
|
|
606
|
-
if method ==
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
638
|
+
if method == "__call__":
|
|
639
|
+
if isinstance(inputs[0], np.ndarray):
|
|
640
|
+
inputs = [inputs[0], inputs[1]]
|
|
641
|
+
for ind, element in enumerate(inputs[0]):
|
|
642
|
+
inputs[0][ind] = ufunc(element, inputs[1], **kwargs)
|
|
643
|
+
return inputs[0]
|
|
644
|
+
elif isinstance(inputs[1], np.ndarray):
|
|
645
|
+
inputs = [inputs[0], inputs[1]]
|
|
646
|
+
for ind, element in enumerate(inputs[1]):
|
|
647
|
+
inputs[1][ind] = ufunc(inputs[0], element, **kwargs)
|
|
648
|
+
return inputs[1]
|
|
649
|
+
else:
|
|
650
|
+
if ufunc == np.add:
|
|
651
|
+
return inputs[0] + inputs[1]
|
|
652
|
+
elif ufunc == np.subtract:
|
|
653
|
+
return inputs[0] - inputs[1]
|
|
654
|
+
elif ufunc == np.multiply:
|
|
655
|
+
return inputs[0] * inputs[1]
|
|
656
|
+
elif ufunc == np.divide:
|
|
657
|
+
return inputs[0] / inputs[1]
|
|
658
|
+
elif ufunc == np.power:
|
|
659
|
+
return inputs[0] ** inputs[1]
|
|
660
|
+
elif ufunc == np.mod:
|
|
661
|
+
return inputs[0] % inputs[1]
|
|
612
662
|
|
|
663
|
+
def __array_function__(self, func, types, *args, **kwargs):
|
|
664
|
+
if func is np.concatenate:
|
|
665
|
+
unit_cache = []
|
|
666
|
+
for arr in args[0]:
|
|
667
|
+
unit_cache += [item.get_unit if isinstance(item, UnitValue) else None for item in arr]
|
|
668
|
+
for i in range(len(arr)):
|
|
669
|
+
arr[i] = arr[i].value if isinstance(arr[i], UnitValue) else arr[i]
|
|
670
|
+
new_array = np.concatenate(args[0], **kwargs)
|
|
671
|
+
for ind, unit in enumerate(unit_cache):
|
|
672
|
+
if unit is not None:
|
|
673
|
+
new_array[ind] = self.create_unit(unit, new_array[ind])
|
|
674
|
+
return new_array
|
|
675
|
+
else:
|
|
676
|
+
return NotImplemented
|
|
677
|
+
|
|
613
678
|
def __convert_system(self, unit: str = "") -> None:
|
|
614
679
|
self.value *= UnitValue.UNITS[self.__system][self.__dimension][self.__unit]
|
|
615
680
|
self.__system = "IMPERIAL" if self.__system == "METRIC" else "METRIC"
|
|
@@ -772,5 +837,4 @@ class UnitValue:
|
|
|
772
837
|
@property
|
|
773
838
|
def get_system(self) -> str:
|
|
774
839
|
return self.__system
|
|
775
|
-
|
|
776
|
-
print(UnitValue.available_units())
|
|
840
|
+
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|