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
pandas2ri.py: Error while trying to convert the column "A". Fall back to string conversion. The error is: 'SparseDtype' object has no attribute 'isnative'
AttributeErrorTraceback (mostrecentcalllast)
/lib/python3.9/site-packages/rpy2/robjects/pandas2ri.py:57, inpy2rpy_pandasdataframe(obj)
56try:
--->57od[name] =conversion.py2rpy(values)
58exceptExceptionase:
File~/.pyenv/versions/3.9.5/lib/python3.9/functools.py:877, insingledispatch.<locals>.wrapper(*args, **kw)
874raiseTypeError(f'{funcname} requires at least '875'1 positional argument')
-->877returndispatch(args[0].__class__)(*args, **kw)
/lib/python3.9/site-packages/rpy2/robjects/pandas2ri.py:191, inpy2rpy_pandasseries(obj)
189# current conversion as performed by numpy-->191res=func(obj.values)
192iflen(obj.shape) ==1:
/lib/python3.9/site-packages/rpy2/robjects/numpy2ri.py:84, innumpy2rpy(o)
82""" Augmented conversion function, converting numpy arrays into 83 rpy2.rinterface-level R structures. """--->84ifnoto.dtype.isnative:
85raiseValueError('Cannot pass numpy arrays with non-native '86'byte orders at the moment.')
AttributeError: 'SparseDtype'objecthasnoattribute'isnative'Duringhandlingoftheaboveexception, anotherexceptionoccurred:
TypeErrorTraceback (mostrecentcalllast)
/lib/python3.9/site-packages/rpy2/rinterface_lib/sexp.py:610, inSexpVector.from_object(cls, obj)
609try:
-->610mv=memoryview(obj)
611res=cls.from_memoryview(mv)
TypeError: memoryview: abytes-likeobjectisrequired, not'Series'Duringhandlingoftheaboveexception, anotherexceptionoccurred:
AttributeErrorTraceback (mostrecentcalllast)
InputIn [280], in<cellline: 4>()
2mat=sparse.eye(3)
3df=pd.DataFrame.sparse.from_spmatrix(mat, columns=['A', 'B', 'C'])
---->4get_ipython().run_line_magic('R', '-i df')
/lib/python3.9/site-packages/IPython/core/interactiveshell.py:2305, inInteractiveShell.run_line_magic(self, magic_name, line, _stack_depth)
2303kwargs['local_ns'] =self.get_local_scope(stack_depth)
2304withself.builtin_trap:
->2305result=fn(*args, **kwargs)
2306returnresult/lib/python3.9/site-packages/rpy2/ipython/rmagic.py:737, inRMagics.R(self, line, cell, local_ns)
735raiseNameError("name '%s' is not defined"%input)
736withlocalconverter(converter) ascv:
-->737ro.r.assign(input, val)
739ifargs.display:
740try:
/lib/python3.9/site-packages/rpy2/robjects/functions.py:198, inSignatureTranslatedFunction.__call__(self, *args, **kwargs)
196v=kwargs.pop(k)
197kwargs[r_k] =v-->198return (super(SignatureTranslatedFunction, self)
199 .__call__(*args, **kwargs))
/lib/python3.9/site-packages/rpy2/robjects/functions.py:117, inFunction.__call__(self, *args, **kwargs)
116def__call__(self, *args, **kwargs):
-->117new_args= [conversion.py2rpy(a) forainargs]
118new_kwargs= {}
119fork, vinkwargs.items():
120# TODO: shouldn't this be handled by the conversion itself ?/lib/python3.9/site-packages/rpy2/robjects/functions.py:117, in<listcomp>(.0)
116def__call__(self, *args, **kwargs):
-->117new_args= [conversion.py2rpy(a) forainargs]
118new_kwargs= {}
119fork, vinkwargs.items():
120# TODO: shouldn't this be handled by the conversion itself ?File~/.pyenv/versions/3.9.5/lib/python3.9/functools.py:877, insingledispatch.<locals>.wrapper(*args, **kw)
873ifnotargs:
874raiseTypeError(f'{funcname} requires at least '875'1 positional argument')
-->877returndispatch(args[0].__class__)(*args, **kw)
/lib/python3.9/site-packages/rpy2/robjects/pandas2ri.py:63, inpy2rpy_pandasdataframe(obj)
58exceptExceptionase:
59warnings.warn('Error while trying to convert '60'the column "%s". Fall back to string conversion. '61'The error is: %s'62% (name, str(e)))
--->63od[name] =StrVector(values)
65returnDataFrame(od)
/lib/python3.9/site-packages/rpy2/robjects/vectors.py:385, inStrVector.__init__(self, obj)
384def__init__(self, obj):
-->385super().__init__(obj)
386self._add_rops()
/lib/python3.9/site-packages/rpy2/rinterface_lib/sexp.py:523, inSexpVector.__init__(self, obj)
521super().__init__(obj)
522elifisinstance(obj, collections.abc.Sized):
-->523super().__init__(self.from_object(obj).__sexp__)
524else:
525raiseTypeError('The constructor must be called '526'with an instance of '527'rpy2.rinterface.Sexp '528'or an instance of '529'rpy2.rinterface._rinterface.SexpCapsule')
/lib/python3.9/site-packages/rpy2/rinterface_lib/sexp.py:614, inSexpVector.from_object(cls, obj)
612except (TypeError, ValueError):
613try:
-->614res=cls.from_iterable(obj)
615exceptValueError:
616msg= ('Theclassmethodsfrom_memoryview() and' 617 'from_iterable() bothfailedtomakea {} ' 618 'fromanobjectofclass {}'
619 .format(cls, type(obj)))
/lib/python3.9/site-packages/rpy2/rinterface_lib/conversion.py:45, in_cdata_res_to_rinterface.<locals>._(*args, **kwargs)
44def_(*args, **kwargs):
--->45cdata=function(*args, **kwargs)
46# TODO: test cdata is of the expected CType47return_cdata_to_rinterface(cdata)
/lib/python3.9/site-packages/rpy2/rinterface_lib/sexp.py:552, inSexpVector.from_iterable(cls, iterable, populate_func, set_elt, cast_value)
547withmemorymanagement.rmemory() asrmemory:
548r_vector=rmemory.protect(
549openrlib.rlib.Rf_allocVector(
550cls._R_TYPE, n)
551 )
-->552populate_func(iterable, r_vector, set_elt, cast_value)
553returnr_vector/lib/python3.9/site-packages/rpy2/rinterface_lib/sexp.py:474, in_populate_r_vector(iterable, r_vector, set_elt, cast_value)
472def_populate_r_vector(iterable, r_vector, set_elt, cast_value):
473fori, vinenumerate(iterable):
-->474set_elt(r_vector, i, cast_value(v))
/lib/python3.9/site-packages/rpy2/rinterface_lib/sexp.py:677, in_as_charsxp_cdata(x)
675returnx.__sexp__._cdata676else:
-->677returnconversion._str_to_charsxp(x)
/lib/python3.9/site-packages/rpy2/rinterface_lib/conversion.py:142, in_str_to_charsxp(val)
140s=rlib.R_NaString141else:
-->142cchar=_str_to_cchar(val, encoding='utf-8')
143s=rlib.Rf_mkCharCE(cchar, openrlib.rlib.CE_UTF8)
144returns/lib/python3.9/site-packages/rpy2/rinterface_lib/conversion.py:121, in_str_to_cchar(s, encoding)
119def_str_to_cchar(s: str, encoding: str='utf-8'):
120# TODO: use isString and installTrChar-->121b=s.encode(encoding)
122returnffi.new('char[]', b)
AttributeError: 'numpy.float64'objecthasnoattribute'encode'
Describe the solution you'd like
Support for converting sparse data frames in rpy2. I know there is https://github.com/rpy2/rpy2-Matrix but it does not cover data frames (and is not published).
Describe alternatives you've considered
Having another package handle this would not be nice for interactive usage.
Additional context
None
The text was updated successfully, but these errors were encountered:
Is your feature request related to a problem? Please describe.
Describe the solution you'd like
Support for converting sparse data frames in rpy2. I know there is https://github.com/rpy2/rpy2-Matrix but it does not cover data frames (and is not published).
Describe alternatives you've considered
Having another package handle this would not be nice for interactive usage.
Additional context
None
The text was updated successfully, but these errors were encountered: