Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'Series' object has no attribute 'applymap' #111

Closed
rebelwebster opened this issue Sep 20, 2018 · 2 comments
Closed

AttributeError: 'Series' object has no attribute 'applymap' #111

rebelwebster opened this issue Sep 20, 2018 · 2 comments

Comments

@rebelwebster
Copy link

Hi Again...
I have another problem :/
The release version of source tracker works absolutely fine but when I download the development version and run exactly the same files, it doesn't work. I am running it with and without the flag --per_sink_feature_assignments (which is why I downloaded the development version). Here's the command and traceback. Any insight?

sourcetracker2 gibbs -i OTU_Table_new.txt -m metadata_new.txt -o OUTPUT

/home/ampere/rlayton/miniconda3/envs/st2/lib/python3.5/site-packages/sourcetracker/_sourcetracker.py:235: FutureWarning: The reduce argument is deprecated and will be removed in a future version. You can specify result_type='reduce' to try to reduce the result to the original dimensions return df.apply(f, axis=1, reduce=False, raw=False) Traceback (most recent call last): File "/home/ampere/rlayton/miniconda3/envs/st2/bin/sourcetracker2", line 11, in <module> sys.exit(cli()) File "/home/ampere/rlayton/miniconda3/envs/st2/lib/python3.5/site-packages/click/core.py", line 722, in __call__ return self.main(*args, **kwargs) File "/home/ampere/rlayton/miniconda3/envs/st2/lib/python3.5/site-packages/click/core.py", line 697, in main rv = self.invoke(ctx) File "/home/ampere/rlayton/miniconda3/envs/st2/lib/python3.5/site-packages/click/core.py", line 1066, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/home/ampere/rlayton/miniconda3/envs/st2/lib/python3.5/site-packages/click/core.py", line 895, in invoke return ctx.invoke(self.callback, **ctx.params) File "/home/ampere/rlayton/miniconda3/envs/st2/lib/python3.5/site-packages/click/core.py", line 535, in invoke return callback(*args, **kwargs) File "/home/ampere/rlayton/miniconda3/envs/st2/lib/python3.5/site-packages/sourcetracker/_cli/gibbs.py", line 234, in gibbs_cli create_feature_tables=per_sink_feature_assignments) File "/home/ampere/rlayton/miniconda3/envs/st2/lib/python3.5/site-packages/sourcetracker/_sourcetracker.py", line 757, in gibbs sources, sinks = validate_gibbs_input(sources, sinks) File "/home/ampere/rlayton/miniconda3/envs/st2/lib/python3.5/site-packages/sourcetracker/_sourcetracker.py", line 60, in validate_gibbs_input if not df.applymap(np.isreal).values.all(): File "/home/ampere/rlayton/miniconda3/envs/st2/lib/python3.5/site-packages/pandas/core/generic.py", line 4376, in __getattr__ return object.__getattribute__(self, name) AttributeError: 'Series' object has no attribute 'applymap'

@johnchase
Copy link
Collaborator

johnchase commented Sep 20, 2018

Can confirm, thanks @rebelwebster for posting this.

This is related to an API change in pandas. pd.apply no longer coerces lists into a dataframe so a series of lists is returned instead.

This should be the offending line https://github.com/biota/sourcetracker2/blob/master/sourcetracker/_sourcetracker.py#L234

f = partial(subsample_counts, n=30, replace=False)
type(ftable.apply(f, axis=1, reduce=False, raw=False))
pandas.core.series.Series

vs:

type(ftable.apply(f, axis=1, raw=False, result_type='broadcast'))
pandas.core.frame.DataFrame

I can probably issue a pull request for this this weekend

@rebelwebster
Copy link
Author

Great, thanks @johnchase

johnchase added a commit to johnchase/sourcetracker2 that referenced this issue Sep 24, 2018
Fixes caporaso-lab#111 Pandas changed the reduce functionality
http://pandas.pydata.org/pandas-docs/stable/whatsnew.html?highlight=rolling_mean#changes-to-make-output-of-dataframe-apply-consistent
the new api is backwards incompatible with >0.23.4. The changes in this
pull request work with both versions of pandas. There may be a better
way to achive this, though I think it is preferable to keep
sourcetracker compatible with the recent versions of pandas
lkursell pushed a commit that referenced this issue Dec 17, 2018
* MAINT: Makes compatible with latest pandas
Fixes #111 Pandas changed the reduce functionality
http://pandas.pydata.org/pandas-docs/stable/whatsnew.html?highlight=rolling_mean#changes-to-make-output-of-dataframe-apply-consistent
the new api is backwards incompatible with >0.23.4. The changes in this
pull request work with both versions of pandas. There may be a better
way to achive this, though I think it is preferable to keep
sourcetracker compatible with the recent versions of pandas

* Added the replace flag back in

* Added the replace flag back in

* updated changelog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants