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

Change type to asset_type in pandas_data.get_asset_by_symbol #388

Merged
merged 6 commits into from
Mar 10, 2024

Conversation

jimwhite
Copy link
Collaborator

@jimwhite jimwhite commented Mar 9, 2024

pandas_data.get_asset_by_symbol used type where it meant asset_type.

There don't appear to be any references to this method in the library so I'm skipping adding/updating a test.

@jimwhite jimwhite requested a review from grzesir as a code owner March 9, 2024 23:49
Copy link
Contributor

@korbit-ai korbit-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My review is in progress 📖 - I will have feedback for you in a few minutes!

Copy link
Contributor

@korbit-ai korbit-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have reviewed your code and found 4 potential issues. To discuss my individual comments that I have added, tag me in replies using @korbit-ai-mentor.


Please react with a 👍 to my comments that you find helpful and a 👎 to those you find unhelpful - this will help me learn and improve as we collaborate.

@@ -171,7 +171,7 @@ def get_last_price(self):
float

"""
return self.df["close"][-1]
return self.df["close"].iloc[-1]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

category Critical Errors priority 7

The use of .iloc[-1] to access the last element of a DataFrame can lead to an error if the DataFrame is empty. It would be better to use the .tail(1) method which returns a DataFrame that can be further processed without errors, even if it's empty.

@@ -185,7 +185,7 @@ def get_last_dividend(self):
float
"""
if "dividend" in self.df.columns:
return self.df["dividend"][-1]
return self.df["dividend"].iloc[-1]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

category Critical Errors priority 7

The use of .iloc[-1] to access the last element of a DataFrame can lead to an error if the DataFrame is empty. It would be better to use the .tail(1) method which returns a DataFrame that can be further processed without errors, even if it's empty.

@@ -233,7 +233,7 @@ def get_momentum(self, start=None, end=None):
if n_rows == 0:
return 0

momentum = df_copy["close"].pct_change(n_rows - 1)[-1]
momentum = df_copy["close"].pct_change(n_rows - 1).iloc[-1]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

category Critical Errors priority 7

The use of .iloc[-1] to access the last element of a DataFrame can lead to an error if the DataFrame is empty. It would be better to use the .tail(1) method which returns a DataFrame that can be further processed without errors, even if it's empty.

Comment on lines +149 to 152
if asset_type is None:
return [asset for asset in store_assets if asset.symbol == symbol]
else:
return [asset for asset in store_assets if (asset.symbol == symbol and asset.asset_type == asset_type)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

category Code Design Improvements priority 6

The change from 'type' to 'asset_type' is a good one, as it makes the code more readable and less prone to confusion. However, it's important to ensure that this change doesn't affect other parts of the codebase. Even though you mentioned that there are no references to this method in the library, it's always a good practice to double-check. Also, it would be beneficial to add a test case for this method to ensure its correct functionality after the change.

@jimwhite
Copy link
Collaborator Author

jimwhite commented Mar 9, 2024

Whoops. I meant to have this change be only the one line in get_asset_by_symbol. Lemme know if you want me to redo this.

Copy link
Contributor

@grzesir grzesir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jimwhite Great work! You are now officially a lumibot contributor, part of the best algo builders in the world. Can't wait to see what you build next.
By the way, let me know if you want some free lumiweralth products, I'd love to support you.

@grzesir grzesir merged commit 54319b7 into Lumiwealth:dev Mar 10, 2024
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants