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

Add locale to Qif.parse() method #87

Closed
wants to merge 2 commits into from

Conversation

foppini975
Copy link

I had to import qif file with Italian locale (using "," as decimal separator), therefore I have added a parameter to Qif.parse() method to specify the locale.

Copy link
Owner

@isaacharrisholt isaacharrisholt left a comment

Choose a reason for hiding this comment

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

This isn't currently functional, and we should try to consider the most basic possible solution.

@@ -395,7 +396,7 @@ def from_list(
field_info.split(" ")[0]
)
elif line_code in {"T", "U"}:
amount = utils.parse_decimal(field_info)
amount = utils.parse_decimal(field_info, locale=locale)
Copy link
Owner

Choose a reason for hiding this comment

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

The utils.parse_decimal function doesn't take a locale argument, so this change won't do anything

@@ -109,6 +109,7 @@ def parse(
separator: str = "\n",
day_first: bool = False,
encoding: str = "utf-8",
locale: str = 'en_US'
Copy link
Owner

Choose a reason for hiding this comment

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

Given the limited number of locales available, would it not be better to use an enum? Perhaps we could have something like:

class DecimalSeparator(enum.Enum):
    PERIOD = "."
    COMMA = ","

Copy link
Owner

@isaacharrisholt isaacharrisholt left a comment

Choose a reason for hiding this comment

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

Babel is a good shout, but please try to be more thorough and consider the wider impacts of the work you're doing. Typically, it's best to discuss changes before implementing them - it's going to be down to me to maintain anything you do that gets merged, and ultimately I need to weigh up the cost of adding new libraries and code.

Usually you'd open an issue first to discuss potential solutions to a problem you're having :)

Comment on lines +125 to +137


Build the Package
=================
Run the following command in the terminal to build the package:
```bash
python setup sdist
```
This command will create a dist/ directory with a source distribution of your library.
Install the local package using pip:
```bash
pip install dist/quiffen-1.0.tar.gz
```
Copy link
Owner

Choose a reason for hiding this comment

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

This is incorrect. Quiffen uses Poetry, so the correct build command is poetry build.

Copy link
Owner

Choose a reason for hiding this comment

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

Also, I'm not sure this is in the scope of this PR. If you'd like to make these changes, please open another PR.

Comment on lines +1 to +15
from setuptools import setup, find_packages

setup(
name='quiffen',
version='1.0',
packages=find_packages(),
install_requires=[
# Your library dependencies
"python >= 3.8",
"pydantic >= 1.10.2",
"pandas >= 1.5.1",
"python-dateutil >= 2.8.2",
"babel >= 2.13.1"
],
)
Copy link
Owner

Choose a reason for hiding this comment

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

Not needed. See previous comments.

@@ -17,6 +17,7 @@
from quiffen.core.class_type import Class
from quiffen.core.investment import Investment
from quiffen.core.split import Split
from babel.numbers import parse_decimal, parse_number
Copy link
Owner

Choose a reason for hiding this comment

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

It doesn't look like you're using parse_number here at all.

Comment on lines 399 to 400
amount = utils.parse_decimal(field_info, locale=locale)
amount = parse_decimal(field_info, locale)
Copy link
Owner

Choose a reason for hiding this comment

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

The utils.parse_decimal function is used in many other places. It might be better to just change the function in utils, and make sure the locale is passed to all callsites.

Also, it might be worth updating docs to show that locale is an option.

@isaacharrisholt
Copy link
Owner

Closing due to inactivity

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

Successfully merging this pull request may close these issues.

2 participants