Skip to content

Commit

Permalink
Merge branch 'master' into allclose
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewgsavage authored Dec 29, 2024
2 parents a922e24 + 974cb2f commit 017eea1
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 25 deletions.
30 changes: 8 additions & 22 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
exclude: '^pint/_vendor'
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 23.7.0
hooks:
- id: black
- id: black-jupyter
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.0.282'
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.7
hooks:
- id: ruff
args: ["--fix"]
args: ["--fix", "--show-fixes"]
types_or: [ python, pyi, jupyter ]
- id: ruff-format
types_or: [ python, pyi, jupyter ]
- repo: https://github.com/executablebooks/mdformat
rev: 0.7.16
rev: 0.7.17
hooks:
- id: mdformat
additional_dependencies:
Expand All @@ -28,15 +26,3 @@ repos:
hooks:
- id: nbstripout
args: [--extra-keys=metadata.kernelspec metadata.language_info.version]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v1.8.0"
hooks:
- id: mypy
verbose: true
args: ["--ignore-missing-imports", "--show-error-codes"]
additional_dependencies: [
"types-requests",
"pandas-stubs",
"pint",
"matplotlib-stubs",
]
2 changes: 1 addition & 1 deletion CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pint-pandas Changelog
0.7 (unreleased)
--------------------

- Nothing added yet
- Added `__array_function__` support for numpy fuctions like clip.


0.6.2 (2024-07-29)
Expand Down
14 changes: 12 additions & 2 deletions pint_pandas/pint_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,11 @@ def __setstate__(self, dct):
self.__dict__.update(dct)
self._Q = self.dtype.ureg.Quantity

def __array_function__(self, func, types, args, kwargs):
args = convert_np_inputs(args)
result = func(*args, **kwargs)
return self._convert_np_result(result)

def __array_ufunc__(self, ufunc, method, *inputs, **kwargs):
out = kwargs.get("out", ())
for x in inputs + out:
Expand All @@ -348,6 +353,8 @@ def _convert_np_result(self, result):
if isinstance(result, bool):
return result
if isinstance(result, _Quantity) and is_list_like(result.m):
if hasattr(result, "ndim") and result.ndim >= 2:
raise ValueError("PintArrays may only be 1D, check axis arguement")
return PintArray.from_1darray_quantity(result)
elif isinstance(result, _Quantity):
return result
Expand All @@ -358,6 +365,8 @@ def _convert_np_result(self, result):
isinstance(item, _Quantity) for item in result
):
return PintArray._from_sequence(result)
elif isinstance(result, np.ndarray):
return result
elif result is None:
# no return value
return result
Expand Down Expand Up @@ -1174,8 +1183,9 @@ def __init__(self, pandas_obj):
def _validate(obj):
if not is_pint_type(obj):
raise AttributeError(
"Cannot use 'pint' accessor on objects of "
"dtype '{}'.".format(obj.dtype)
"Cannot use 'pint' accessor on objects of " "dtype '{}'.".format(
obj.dtype
)
)

@staticmethod
Expand Down
1 change: 1 addition & 0 deletions pint_pandas/testsuite/test_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ def test_issue246(self):


class TestArrayFunction(BaseExtensionTests):

def test_issue255(self):
a = np.r_[1, 2, np.nan, 4, 10]
pa = PintArray.from_1darray_quantity(a * ureg.m)
Expand Down
8 changes: 8 additions & 0 deletions pint_pandas/testsuite/test_pandas_extensiontests.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,3 +603,11 @@ def test_EA_types(self, engine, data, request):
@pytest.mark.skip("TODO: fix this test")
def test_array_interface_copy(self, data):
pass

@pytest.mark.skip(reason="not implemented in pint")
def test_repeat(self):
pass

@pytest.mark.skip(reason="not implemented in pint")
def test_repeat_raises(self):
pass
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ ignore = [
"E731",
# line break before binary operator
# "W503"
"F811",
]
extend-exclude = ["build"]
line-length=88
Expand Down

0 comments on commit 017eea1

Please sign in to comment.