You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest released version of Modin.
I have confirmed this bug exists on the main branch of Modin. (In order to do this you can follow this guide.)
Reproducible Example
importmodin.pandasaspdimportpandasclassCustomNumber():
def__init__(self, value: int):
self.value=valuedef__add__(self, other):
returnself.value+otherdef__radd__(self, other):
returnother+self.value# pandas works without error and gives series of [5]print(pandas.Series([1]) +CustomNumber(4))
# modin raises errorprint(pd.Series([1]) +CustomNumber(4))
Issue Description
other is not a scalar in _validate_otherhere, so we check dtype here and raise TypeError.
Expected Behavior
Can add custom classes that overload addition operators to pandas objects.
Error Logs
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Input In [1], in <cell line: 15>()
13print(pandas.Series([1]) + CustomNumber(4))
14# raises error
---> 15 print(pd.Series([1]) + CustomNumber(4))
File ~/software_sources/modin/modin/logging/logger_decorator.py:128, in enable_logging.<locals>.decorator.<locals>.run_and_log(*args, **kwargs)
113"""114 Compute function with logging if Modin logging is enabled.
115
(...)
125 Any
126"""127if LogMode.get() =="disable":
--> 128 return obj(*args, **kwargs)
130 logger = get_logger()
131 logger_level =getattr(logger, log_level)
File ~/software_sources/modin/modin/pandas/series.py:172, in Series.__add__(self, right)
170@_doc_binary_op(operation="addition", bin_op="add")
171def__add__(self, right):
--> 172 return self.add(right)
File ~/software_sources/modin/modin/logging/logger_decorator.py:128, in enable_logging.<locals>.decorator.<locals>.run_and_log(*args, **kwargs)
113"""114 Compute function with logging if Modin logging is enabled.
115
(...)
125 Any
126"""127if LogMode.get() =="disable":
--> 128 return obj(*args, **kwargs)
130 logger = get_logger()
131 logger_level =getattr(logger, log_level)
File ~/software_sources/modin/modin/pandas/series.py:495, in Series.add(self, other, level, fill_value, axis)
491"""492 Return Addition of series and other, element-wise (binary operator add).
493"""494 new_self, new_other =self._prepare_inter_op(other)
--> 495 return super(Series, new_self).add(
496 new_other, level=level, fill_value=fill_value, axis=axis
497 )
File ~/software_sources/modin/modin/logging/logger_decorator.py:128, in enable_logging.<locals>.decorator.<locals>.run_and_log(*args, **kwargs)
113"""114 Compute function with logging if Modin logging is enabled.
115
(...)
125 Any
126"""127if LogMode.get() =="disable":
--> 128 return obj(*args, **kwargs)
130 logger = get_logger()
131 logger_level =getattr(logger, log_level)
File ~/software_sources/modin/modin/pandas/base.py:571, in BasePandasDataset.add(self, other, axis, level, fill_value)
565defadd(
566self, other, axis="columns", level=None, fill_value=None567 ): # noqa: PR01, RT01, D200568"""569 Return addition of `BasePandasDataset`and`other`, element-wise (binary operator `add`).
570"""
--> 571 return self._binary_op(
572"add", other, axis=axis, level=level, fill_value=fill_value
573 )
File ~/software_sources/modin/modin/logging/logger_decorator.py:128, in enable_logging.<locals>.decorator.<locals>.run_and_log(*args, **kwargs)
113"""114 Compute function with logging if Modin logging is enabled.
115
(...)
125 Any
126"""127if LogMode.get() =="disable":
--> 128 return obj(*args, **kwargs)
130 logger = get_logger()
131 logger_level =getattr(logger, log_level)
File ~/software_sources/modin/modin/pandas/base.py:396, in BasePandasDataset._binary_op(self, op, other, **kwargs)
392 kwargs.pop("broadcast", None)
393returnself._default_to_pandas(
394getattr(self._pandas_class, op), other, **kwargs
395 )
--> 396 other = self._validate_other(other, axis, dtype_check=True)
397 exclude_list = [
398"__add__",
399"__radd__",
(...)
405"__rxor__",
406 ]
407if op in exclude_list:
File ~/software_sources/modin/modin/logging/logger_decorator.py:128, in enable_logging.<locals>.decorator.<locals>.run_and_log(*args, **kwargs)
113"""114 Compute function with logging if Modin logging is enabled.
115
(...)
125 Any
126"""127if LogMode.get() =="disable":
--> 128 return obj(*args, **kwargs)
130 logger = get_logger()
131 logger_level =getattr(logger, log_level)
File ~/software_sources/modin/modin/pandas/base.py:317, in BasePandasDataset._validate_other(self, other, axis, dtype_check, compare_index)
299 self_dtypes = [
300 dtype
301for label, dtype inzip(
(...)
304if label in other
305 ]
307ifnotall(
308 (is_numeric_dtype(self_dtype) and is_numeric_dtype(other_dtype))
309or (is_object_dtype(self_dtype) and is_object_dtype(other_dtype))
(...)
315for self_dtype, other_dtype inzip(self_dtypes, other_dtypes)
316 ):
--> 317 raise TypeError("Cannot do operation with improper dtypes")
318return result
TypeError: Cannot do operation with improper dtypes
Installed Versions
INSTALLED VERSIONS
commit : fd776a5
python : 3.8.13.final.0
python-bits : 64
OS : Darwin
OS-release : 21.5.0
Version : Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:22 PDT 2022; root:xnu-8020.121.3~4/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
Modin version checks
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest released version of Modin.
I have confirmed this bug exists on the main branch of Modin. (In order to do this you can follow this guide.)
Reproducible Example
Issue Description
other
is not a scalar in_validate_other
here, so we check dtype here and raiseTypeError
.Expected Behavior
Can add custom classes that overload addition operators to pandas objects.
Error Logs
Installed Versions
INSTALLED VERSIONS
commit : fd776a5
python : 3.8.13.final.0
python-bits : 64
OS : Darwin
OS-release : 21.5.0
Version : Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:22 PDT 2022; root:xnu-8020.121.3~4/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
Modin dependencies
modin : 0.17.0+9.gfd776a5a
ray : 2.0.1
dask : 2022.01.1
distributed : 2022.01.1
hdk : None
pandas dependencies
pandas : 1.5.1
numpy : 1.23.1
pytz : 2022.1
dateutil : 2.8.2
setuptools : 61.2.0
pip : 22.1.2
Cython : None
pytest : 7.1.2
hypothesis : None
sphinx : 5.1.1
blosc : None
feather : 0.4.1
xlsxwriter : None
lxml.etree : 4.9.1
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.4.0
pandas_datareader: None
bs4 : 4.11.1
bottleneck : None
brotli : None
fastparquet : 2022.11.0
fsspec : 2022.7.1
gcsfs : None
matplotlib : 3.5.2
numba : None
numexpr : 2.8.3
odfpy : None
openpyxl : 3.0.10
pandas_gbq : 0.17.7
pyarrow : 8.0.0
pyreadstat : None
pyxlsb : None
s3fs : 2022.7.1
scipy : 1.9.0
snappy : None
sqlalchemy : 1.4.39
tables : 3.7.0
tabulate : None
xarray : 2022.6.0
xlrd : 2.0.1
xlwt : None
zstandard : None
tzdata : None
The text was updated successfully, but these errors were encountered: