From 8597cd7397824d9e1d1609e57ffac15d55b7a481 Mon Sep 17 00:00:00 2001 From: MarcoGorelli <33491632+MarcoGorelli@users.noreply.github.com> Date: Wed, 29 Nov 2023 14:19:20 +0100 Subject: [PATCH 1/2] fixup right operations --- .../pandas_standard/scalar_object.py | 16 ++++++++-------- .../polars_standard/scalar_object.py | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/dataframe_api_compat/pandas_standard/scalar_object.py b/dataframe_api_compat/pandas_standard/scalar_object.py index aee084b5..d609efb8 100644 --- a/dataframe_api_compat/pandas_standard/scalar_object.py +++ b/dataframe_api_compat/pandas_standard/scalar_object.py @@ -59,7 +59,7 @@ def _materialise(self) -> Any: def persist(self) -> Scalar: return Scalar( self._value, - df=self._df, + df=None, api_version=self._api_version, is_persisted=True, ) @@ -110,7 +110,7 @@ def __radd__(self, other: Any) -> Scalar: other = validate_comparand(self, other) if other is NotImplemented: return NotImplemented - return self._from_scalar(self._value.__radd__(other)) + return self._from_scalar(other + self._value) def __sub__(self, other: Any) -> Scalar: other = validate_comparand(self, other) @@ -122,7 +122,7 @@ def __rsub__(self, other: Any) -> Scalar: other = validate_comparand(self, other) if other is NotImplemented: return NotImplemented - return self._from_scalar(self._value.__rsub__(other)) + return self._from_scalar(other - self._value) def __mul__(self, other: Any) -> Scalar: other = validate_comparand(self, other) @@ -134,7 +134,7 @@ def __rmul__(self, other: Any) -> Scalar: other = validate_comparand(self, other) if other is NotImplemented: return NotImplemented - return self._from_scalar(self._value.__rmul__(other)) + return self._from_scalar(other * self._value) def __mod__(self, other: Any) -> Scalar: other = validate_comparand(self, other) @@ -146,7 +146,7 @@ def __rmod__(self, other: Any) -> Scalar: other = validate_comparand(self, other) if other is NotImplemented: return NotImplemented - return self._from_scalar(self._value.__rmod__(other)) + return self._from_scalar(other % self._value) def __pow__(self, other: Any) -> Scalar: other = validate_comparand(self, other) @@ -158,7 +158,7 @@ def __rpow__(self, other: Any) -> Scalar: other = validate_comparand(self, other) if other is NotImplemented: return NotImplemented - return self._from_scalar(self._value.__rpow__(other)) + return self._from_scalar(other**self._value) def __floordiv__(self, other: Any) -> Scalar: other = validate_comparand(self, other) @@ -170,7 +170,7 @@ def __rfloordiv__(self, other: Any) -> Scalar: other = validate_comparand(self, other) if other is NotImplemented: return NotImplemented - return self._from_scalar(self._value.__rfloordiv__(other)) + return self._from_scalar(other // self._value) def __truediv__(self, other: Any) -> Scalar: other = validate_comparand(self, other) @@ -182,7 +182,7 @@ def __rtruediv__(self, other: Any) -> Scalar: other = validate_comparand(self, other) if other is NotImplemented: return NotImplemented - return self._from_scalar(self._value.__rtruediv__(other)) + return self._from_scalar(other / self._value) def __neg__(self) -> Scalar: return self._from_scalar(self._value.__neg__()) diff --git a/dataframe_api_compat/polars_standard/scalar_object.py b/dataframe_api_compat/polars_standard/scalar_object.py index 32fa51e6..a48ac62e 100644 --- a/dataframe_api_compat/polars_standard/scalar_object.py +++ b/dataframe_api_compat/polars_standard/scalar_object.py @@ -71,7 +71,7 @@ def persist(self) -> Scalar: value = df.get_column(df.columns[0]).item() return Scalar( value, - df=self._df, + df=None, api_version=self._api_version, is_persisted=True, ) @@ -122,7 +122,7 @@ def __radd__(self, other: Any) -> Scalar: other = validate_comparand(self, other) if other is NotImplemented: return NotImplemented - return self._from_scalar(self._value.__radd__(other)) + return self._from_scalar(other + self._value) def __sub__(self, other: Any) -> Scalar: other = validate_comparand(self, other) @@ -134,7 +134,7 @@ def __rsub__(self, other: Any) -> Scalar: other = validate_comparand(self, other) if other is NotImplemented: return NotImplemented - return self._from_scalar(self._value.__rsub__(other)) + return self._from_scalar(other - self._value) def __mul__(self, other: Any) -> Scalar: other = validate_comparand(self, other) @@ -146,7 +146,7 @@ def __rmul__(self, other: Any) -> Scalar: other = validate_comparand(self, other) if other is NotImplemented: return NotImplemented - return self._from_scalar(self._value.__rmul__(other)) + return self._from_scalar(other * self._value) def __mod__(self, other: Any) -> Scalar: other = validate_comparand(self, other) @@ -158,7 +158,7 @@ def __rmod__(self, other: Any) -> Scalar: other = validate_comparand(self, other) if other is NotImplemented: return NotImplemented - return self._from_scalar(self._value.__rmod__(other)) + return self._from_scalar(other % self._value) def __pow__(self, other: Any) -> Scalar: other = validate_comparand(self, other) @@ -170,7 +170,7 @@ def __rpow__(self, other: Any) -> Scalar: other = validate_comparand(self, other) if other is NotImplemented: return NotImplemented - return self._from_scalar(self._value.__rpow__(other)) + return self._from_scalar(other**self._value) def __floordiv__(self, other: Any) -> Scalar: other = validate_comparand(self, other) @@ -182,7 +182,7 @@ def __rfloordiv__(self, other: Any) -> Scalar: other = validate_comparand(self, other) if other is NotImplemented: return NotImplemented - return self._from_scalar(self._value.__rfloordiv__(other)) + return self._from_scalar(other // self._value) def __truediv__(self, other: Any) -> Scalar: other = validate_comparand(self, other) @@ -194,7 +194,7 @@ def __rtruediv__(self, other: Any) -> Scalar: other = validate_comparand(self, other) if other is NotImplemented: return NotImplemented - return self._from_scalar(self._value.__rtruediv__(other)) + return self._from_scalar(other / self._value) def __neg__(self) -> Scalar: return self._from_scalar(self._value.__neg__()) From 02516fd12bd2ac7ffdd2b325621febdad81588ab Mon Sep 17 00:00:00 2001 From: MarcoGorelli <33491632+MarcoGorelli@users.noreply.github.com> Date: Wed, 29 Nov 2023 14:22:35 +0100 Subject: [PATCH 2/2] pre --- .github/workflows/tox.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tox.yml b/.github/workflows/tox.yml index e60ef267..49d6a673 100644 --- a/.github/workflows/tox.yml +++ b/.github/workflows/tox.yml @@ -60,7 +60,7 @@ jobs: ~\AppData\Local\pip\Cache key: ${{ runner.os }}-build-${{ matrix.python-version }} - name: install-reqs - run: python -m pip install --upgrade tox virtualenv setuptools pip -r --pre requirements-dev.txt + run: python -m pip install --pre --upgrade tox virtualenv setuptools pip -r requirements-dev.txt - name: Run pytest run: pytest tests --cov=dataframe_api_compat --cov=tests --cov-fail-under=50 # todo: add mypy here too!