ACCLAB / DABEST-python

Data Analysis with Bootstrapped ESTimation
https://acclab.github.io/DABEST-python/
Apache License 2.0
337 stars 46 forks source link

cannot plot figure - 'numpy.ndarray' object has no attribute 'categories' #167

Closed brankraj closed 4 months ago

brankraj commented 5 months ago

Hi, I am trying to learn and use Dabest stats, all code on 'dabest - Basics' with randomly generated data works, but when I try to use my specific, non-random data, the plotting results in an error : AttributeError: 'numpy.ndarray' object has no attribute 'categories'

(the the last step that works for me: pd.options.display.max_columns = 50two_groups_unpaired.mean_diff.results - I get the table with stats results)

my noob code is:

import numpy as np import pandas as pd import dabest

cc = [0.09, 0.23, 0.04, -0.05, 0.08, 0.13, -0.03, -0.05] mm = [0.39, 0.39, 0.36, 0.52, 0.36, 0.44, 0.33, 0.33]

df_exp2_ss = pd.DataFrame({'CC' : cc, 'MM': mm}) from scipy.stats import norm # Used in generation of populations.

np.random.seed(9999) # Fix the seed so the results are replicable.

pop_size = 10000 # Size of each population.

Ns = 20 # The number of samples taken from each populationfrom scipy.stats import norm # Used in generation of populations.

number_of_allgroups = 2

Add an id column for paired data plotting.

id_col = pd.Series(range(1, number_of_allgroups+1))

Ns = 8 # The number of samples taken from each population

Add a gender column for coloring the data.

females = np.repeat('Female', Ns/2).tolist() males = np.repeat('Male', Ns/2).tolist() gender = females + males

Add an id column for paired data plotting.

id_col = pd.Series(range(1, Ns+1))

Combine samples and gender into a DataFrame.

df_exp2_ss = pd.DataFrame({'CC' : cc, 'MM' : mm, 'Gender' : gender, 'ID' : id_col })

print(df_exp2_ss.dtypes)

print(df_exp2_ss.dtypes) CC float64 MM float64 Gender object ID int64 dtype: object

two_groups_unpaired = dabest.load(df_exp2_ss, idx=('CC', 'MM'), paired=None)

two_groups_unpaired

two_groups_unpaired.mean_diff

pd.options.display.max_columns = 50 two_groups_unpaired.mean_diff.results

Last step that gets me error: my_data = dabest.load(df_exp2_ss, idx=("CC", "MM")) fig1 = my_data.mean_diff.plot()

I also tried replacing my_data with the name of my data frame df_exp2_ss, same error

ERROR:

AttributeError Traceback (most recent call last) Cell In[216], line 2 1 df_exp2_ss = dabest.load(df_exp2_ss, idx=("CC", "MM")) ----> 2 fig1 = df_exp2_ss.mean_diff.plot()

File ~\anaconda3\envs\dabest\Lib\site-packages\dabest_classes.py:3129, in EffectSizeDataFrame.plot(self, color_col, raw_marker_size, es_marker_size, swarm_label, barchart_label, contrast_label, delta2_label, swarm_ylim, barchart_ylim, contrast_ylim, delta2_ylim, custom_palette, swarm_desat, halfviolin_desat, halfviolin_alpha, face_color, bar_label, bar_desat, bar_width, bar_ylim, ci, ci_type, err_color, float_contrast, show_pairs, show_delta2, show_mini_meta, group_summaries, group_summaries_offset, fig_size, dpi, ax, swarmplot_kwargs, barplot_kwargs, violinplot_kwargs, slopegraph_kwargs, sankey_kwargs, reflines_kwargs, group_summary_kwargs, legend_kwargs) 3126 all_kwargs = locals() 3127 del all_kwargs["self"] -> 3129 out = EffectSizeDataFramePlotter(self, **all_kwargs) 3131 return out

File ~\anaconda3\envs\dabest\Lib\site-packages\dabest\plotter.py:248, in EffectSizeDataFramePlotter(EffectSizeDataFrame, **plot_kwargs) 246 if custom_pal is None and color_col is None: 247 swarm_colors = [sns.desaturate(c, swarm_desat) for c in unsat_colors] --> 248 plot_palette_raw = dict(zip(names.categories, swarm_colors)) 250 bar_color = [sns.desaturate(c, bar_desat) for c in unsat_colors] 251 plot_palette_bar = dict(zip(names.categories, bar_color))

AttributeError: 'numpy.ndarray' object has no attribute 'categories'

- print(pd.version) 2.1.4 dabest.version '2023.02.14'

Thank you!

Jacobluke- commented 5 months ago

Hi @brankraj , thanks for raising this issue. Would you mind checking out the branch vnbdev and use pip install . in Command Line to try out the newest version of DABEST-python and see if the problem persist?

brankraj commented 5 months ago

Hi @Jacobluke, reinstalling pip and scipy helped. Bumpy start with python for me, thank you for your help! Best