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

Example in README returns error #1

Open
CurtLH opened this issue Jul 22, 2022 · 5 comments
Open

Example in README returns error #1

CurtLH opened this issue Jul 22, 2022 · 5 comments

Comments

@CurtLH
Copy link

CurtLH commented Jul 22, 2022

I'm hoping to learn how to use this package, but when I run the example in the README, I get the following error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [2], in <cell line: 1>()
----> 1 main()

Input In [1], in main()
     26 sensitive_column = "col4"
     28 p = anonypy.Preserver(df, feature_columns, sensitive_column)
---> 29 rows = p.anonymize_k_anonymity(k=2)
     31 dfn = pd.DataFrame(rows)
     32 print(dfn)

File ~/miniconda3/envs/ppla-dev2/lib/python3.8/site-packages/anonypy/anonypy.py:18, in Preserver.anonymize_k_anonymity(self, k)
     17 def anonymize_k_anonymity(self, k):
---> 18     return self.__anonymize(k)

File ~/miniconda3/envs/ppla-dev2/lib/python3.8/site-packages/anonypy/anonypy.py:10, in Preserver.__anonymize(self, k, l, p)
      8 def __anonymize(self, k, l=0, p=0.0):
      9     partitions = self.modrian.partition(k, l, p)
---> 10     return anonymize(
     11         self.modrian.df,
     12         partitions,
     13         self.modrian.feature_columns,
     14         self.modrian.sensitive_column,
     15     )

File ~/miniconda3/envs/ppla-dev2/lib/python3.8/site-packages/anonypy/anonypy.py:79, in anonymize(df, partitions, feature_columns, sensitive_column, max_partitions)
     75 grouped_columns = df.loc[partition].agg(aggregations, squeeze=False)
     76 sensitive_counts = (
     77     df.loc[partition].groupby(sensitive_column).agg({sensitive_column: "count"})
     78 )
---> 79 values = grouped_columns.iloc[0].to_dict()
     80 for sensitive_value, count in sensitive_counts[sensitive_column].items():
     81     if count == 0:

AttributeError: 'list' object has no attribute 'to_dict'
@gianmarcoaversanoenx
Copy link

+1

1 similar comment
@MorTzadok
Copy link

+1

@AshtonIzmev
Copy link

I had the same problem but when I tried to debug the code locally (using a single file containing all concatenated functions), it worked.

@IamWorld
Copy link

IamWorld commented Mar 1, 2024

I was able to make it work, I had to change the file anonypy.py on the lines 79 and 108

Replacing this line

values = grouped_columns.iloc[0].to_dict()

with this one

values= {}
for name,val in grouped_columns.items():
values[name] = val[0]

Hope it helps.

@glassonion1
Copy link
Owner

glassonion1 commented Sep 21, 2024

@CurtLH
Thank you for all the messages.
I've updated the dependent libraries and resolved the errors. I just released version 0.2.1, so please try using it.

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

6 participants