caporaso-lab / sourcetracker2

SourceTracker2
BSD 3-Clause "New" or "Revised" License
61 stars 45 forks source link

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

Closed rebelwebster closed 5 years ago

rebelwebster commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

Great, thanks @johnchase