fix: from csv behaviour#646
Conversation
Codecov Report
@@ Coverage Diff @@
## main #646 +/- ##
==========================================
+ Coverage 86.45% 86.46% +0.01%
==========================================
Files 133 133
Lines 6755 6761 +6
==========================================
+ Hits 5840 5846 +6
Misses 915 915
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
ee85ce3 to
9db093a
Compare
|
I believe this can be solved inside |
32656f7 to
60a6784
Compare
|
Thanks for the review, @JoanFM! I think, unfortunately, cls is always a class, even when the classmethod is called from an instance. Therefore, I had a quick chat with Johannes yesterday and he recommended me to follow the approach from jina-ai/serve#4787. Let me know if I’m missing something. |
|
Do not add an |
Are we sure about this? It would assign some methods that don't exist there and break separation of concerns. It seems to be accepted practice to let mixins have inits and pass **kwargs between them: https://stackoverflow.com/a/50465583 |
multiple inheritance is not so easily supported in Python I think. What is ur super when u call super? |
My understanding is that |
I agree with Johannes it would be better to add it in the Mixin |
Do not put it there. Mixins should be stateless |
But by moving it to the base class we don't avoid the state, we just move it to somewhere else. The only thing that changes is that the assignment happens somewhere where we don't know the thing that we assign... But not willing to die in this hill, @anna-charlotte you can choose who to listen to ;) |
What doesn't need state is the Mixin, not the class. |
|
Anyaway, the error came from not passing positional |
I don't agree, the only 'state' we have is which implementation of |
JoanFM
left a comment
There was a problem hiding this comment.
sorry, not approved, let's raise Exception
| """ | ||
| warnings.warn( | ||
| 'Calling from_csv() from a DocumentArray instance does not change the instance in-place. Instead of calling from_csv() from a DocumentArray instance, you should probably use `DocumentArray.from_csv(...)`.' | ||
| raise Exception( |
There was a problem hiding this comment.
Not any Exception, we need to raise the same Exception pandas raise when trying to load from_csv from pandas.Dataframe instance
There was a problem hiding this comment.
I can't find a from_csv in pandas, only pd.read_csv (no classmethod) or classmethods like from_dict. from_dict does not throw an exception when being called from an instance, I believe. Am I missing something?
There was a problem hiding this comment.
The idea it that when you try to do
import pandas as pd
df = pd.DataFrame()
df.read_csv()
>>> AttributeError: 'DataFrame' object has no attribute 'read_csv'it will fail because the df object does not have the read_csv method. We want to mimic the behavior but I am not sure if we should have exactly the same error message.
@JoanFM what about raising
AttributeError: 'from_csv can't be called from a DocumentArray instance directly but rather from the DocumentArray class
There was a problem hiding this comment.
thank you! Changed it now.
samsja
left a comment
There was a problem hiding this comment.
Looks good so far ! Next step is to make it a bit more generic so that it work for the all of the from_xxx classmethod
|
I might move the generalization regarding all of the |
Goals: