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

[REVIEW] Add support for decimal128 in cudf python #9533

Merged
merged 128 commits into from
Jan 18, 2022

Conversation

galipremsagar
Copy link
Contributor

@galipremsagar galipremsagar commented Oct 27, 2021

Resolves: #10031

Depends on #9483, #9986

Note: The CI for this PR is not going to pass until #9986 is admin-merged(Admin merge needed since #9986 requires this PR changes too).

  • Introduced Decimal128Dtype and Decimal128Column.
  • Enabled python side support for the above both.
  • Enables complete support for Decimal32Column which is currently lacking.
  • Enabled orc writer to use decimal128.
  • Enabled parquet to read a decimal128 type.
  • Enabled Scalar support for Decimal128Dtype.
  • Covered all decimal types in string <-> decimal conversions.
  • Made Decimal128Dtype the default type while reading in a Decimal Series or Scalar. User can specify to choose a specific decimal type by passing a dtype. (Breaking)
  • Fixed issues in the binop precision & scale calculation logic to correctly choose a decimal type. (Breaking)
  • Fixed type metadata handling issues seen across APIs while making changes.
  • Added parametrizations for all missing decimal32 tests.
  • Added parametrizations for decimal128 along with existing decimal type-specific tests.

@galipremsagar galipremsagar requested a review from vyasr January 14, 2022 20:41
Copy link
Contributor

@vuule vuule left a comment

Choose a reason for hiding this comment

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

optional suggestion

python/cudf/cudf/_lib/orc.pyx Outdated Show resolved Hide resolved
Copy link
Contributor

@vyasr vyasr 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 a couple final small suggestions but I'm going ahead and approving right now. It looks great!

python/cudf/cudf/core/dtypes.py Outdated Show resolved Hide resolved
Comment on lines 526 to 528
name = "decimal128"
MAX_PRECISION = 38
itemsize = 16
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know if we have a convention for class variables being upper or lower case, but I would suggest being consistent at least within these classes in lieu of a broader rule. It is odd to see MAX_PRECISION capitalized while itemsize is lowercase.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In column.pyx we use itemsize attribute to calculate a columns base_size:

@property
    def base_size(self):
        return int(self.base_data.size / self.dtype.itemsize)

Should we capitalize class constant to ITEMSIZE and introduce a property in parent DecimalType class that just returns the class constant?

@property
def itemsize(self):
      return self.ITEMSIZE

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did the above changes, if you think it was unnecessary let me know I'll revert it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Unless it needs to be evaluated per instance per access, there's no need for a property IMO. A lowercase attribute (for consistency with np.dtype) is fine.

Copy link
Contributor

Choose a reason for hiding this comment

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

I take that back, a property does effectively make this a read-only attribute..

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah I missed that numpy.dtype has an itemsize attribute and that we needed to match that. @shwina IMO in general we shouldn't use properties over class attributes just to enforce immutability. If something really belongs to the class, not to instances, I think it is more Pythonic to put it in the class and allow users to shoot themselves in the foot by modifying it (as long as we document appropriately). That said, in this case we should match whatever numpy is doing, so @galipremsagar's solution looks fine to me.

ajschmidt8 pushed a commit that referenced this pull request Jan 18, 2022
Resolves C++ side of #9980.

The reason this PR is breaking is because Arrow only has a notion of `decimal128` (see `arrow::Type::DECIMAL`). We can still support both `decimal64` **and** `decimal128` for `to_arrow` but for `from_arrow` it only makes sense to support one of them, and `decimal128` (now that we have it) is the logical choice. Therfore, the switching of the return type of a column coming `from_arrow` from `decimal64` to `decimal128` is a breaking change.

Requires:
* #7314
* #9533

Authors:
   - Conor Hoekstra (https://github.com/codereport)

Approvers:
   - Devavret Makkar (https://github.com/devavret)
   - Mike Wilson (https://github.com/hyperbolic2346)
@codecov
Copy link

codecov bot commented Jan 18, 2022

Codecov Report

Merging #9533 (e4ccbb2) into branch-22.02 (967a333) will decrease coverage by 0.07%.
The diff coverage is n/a.

Impacted file tree graph

@@               Coverage Diff                @@
##           branch-22.02    #9533      +/-   ##
================================================
- Coverage         10.49%   10.41%   -0.08%     
================================================
  Files               119      119              
  Lines             20305    20541     +236     
================================================
+ Hits               2130     2139       +9     
- Misses            18175    18402     +227     
Impacted Files Coverage Δ
python/custreamz/custreamz/kafka.py 29.16% <0.00%> (-0.63%) ⬇️
python/dask_cudf/dask_cudf/sorting.py 92.66% <0.00%> (-0.25%) ⬇️
python/dask_cudf/dask_cudf/core.py 70.85% <0.00%> (-0.17%) ⬇️
python/cudf/cudf/__init__.py 0.00% <0.00%> (ø)
python/cudf/cudf/api/types.py 0.00% <0.00%> (ø)
python/cudf/cudf/core/frame.py 0.00% <0.00%> (ø)
python/cudf/cudf/core/index.py 0.00% <0.00%> (ø)
python/cudf/cudf/io/parquet.py 0.00% <0.00%> (ø)
python/cudf/cudf/core/dtypes.py 0.00% <0.00%> (ø)
python/cudf/cudf/core/scalar.py 0.00% <0.00%> (ø)
... and 31 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 45c20d1...e4ccbb2. Read the comment docs.

@galipremsagar
Copy link
Contributor Author

@gpucibot merge

@galipremsagar galipremsagar added 5 - Ready to Merge Testing and reviews complete, ready to merge and removed 3 - Ready for Review Ready for review by team 4 - Needs cuDF (Python) Reviewer labels Jan 18, 2022
@galipremsagar
Copy link
Contributor Author

rerun tests

@rapids-bot rapids-bot bot merged commit 8d7330f into rapidsai:branch-22.02 Jan 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5 - Ready to Merge Testing and reviews complete, ready to merge breaking Breaking change feature request New feature or request Python Affects Python cuDF API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEA] Enable Decimal128 support in cudf python
7 participants