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

dataframe value changed after inserted to Decimal() type column using insert_dataframe() method #258

Open
zsmeijin opened this issue Oct 20, 2021 · 0 comments

Comments

@zsmeijin
Copy link

Describe the bug
dataframe value changed after insert to Decimal() type column using insert_dataframe() method.
In Class DecimalColumn method before_write_items, value is scaled before inserted, it seems done by reference and scales dataframe column's value directly. it is confusing to have dataframe's value changed without notice

    def before_write_items(self, items, nulls_map=None):
        null_value = self.null_value

        if self.scale >= 1:
            scale = 10 ** self.scale

            for i, item in enumerate(items):
                if nulls_map and nulls_map[i]:
                    items[i] = null_value
                else:
                    items[i] = int(Decimal(str(item)) * scale)

        else:
            for i, item in enumerate(items):
                if nulls_map and nulls_map[i]:
                    items[i] = null_value
                else:
                    items[i] = int(Decimal(str(item)))

To Reproduce
create a table contains Decimal column, and using insert_dataframe() insert a dataframe

Expected behavior
dataframe unchanged after insert

Versions
package version: 0.2.2
python version: 3.8.9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants