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

With numpy>=1.24, np.int is deprecated #2378

Closed
saiwing-yeung opened this issue May 9, 2023 · 2 comments
Closed

With numpy>=1.24, np.int is deprecated #2378

saiwing-yeung opened this issue May 9, 2023 · 2 comments

Comments

@saiwing-yeung
Copy link

Problem: With numpy>=1.24, np.int is deprecated but still used in catboost
catboost version: 1.2
Operating System: Debian
CPU: Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz
GPU: not used

MWE: Using the example from https://catboost.ai/en/docs/concepts/python-usages-examples

from catboost import CatBoostRegressor
# Initialize data

train_data = [[1, 4, 5, 6],
              [4, 5, 6, 7],
              [30, 40, 50, 60]]

eval_data = [[2, 4, 6, 8],
             [1, 4, 50, 60]]

train_labels = [10, 20, 30]
# Initialize CatBoostRegressor
model = CatBoostRegressor(iterations=2,
                          learning_rate=1,
                          depth=2)
# Fit model
model.fit(train_data, train_labels)
# Get predictions
preds = model.predict(eval_data)
preds

This all works.

But model.calc_feature_statistics(train_data, train_labels) would return:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [2], in <cell line: 1>()
----> 1 model.calc_feature_statistics(train_data, train_labels)

File /opt/my_dir/.venv/lib/python3.9/site-packages/catboost/core.py:3801, in CatBoost.calc_feature_statistics(self, data, target, feature, prediction_type, cat_feature_values, plot, max_cat_features_on_plot, thread_count, plot_file)
   3799         float_features_nums.append(feature_internal_index)
   3800         feature_type_mapper.append('float')
-> 3801 results = [self._object._get_binarized_statistics(
   3802     data_item,
   3803     cat_features_nums,
   3804     float_features_nums,
   3805     prediction_type,
   3806     thread_count
   3807 ) for data_item in data]
   3808 # res = [dict,   dict,   ...,   dict,  dict,   dict,   ...,   dict ]
   3809 #        |  stat for cat features  |  |  stat for float features  |
   3810 statistics_by_feature = defaultdict(list)

[snip]

AttributeError: module 'numpy' has no attribute 'int'.
`np.int` was a deprecated alias for the builtin `int`. To avoid this error in existing code, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` to specify the precision. If you wish to review your current use, check the release note link for additional information.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
    https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations

https://numpy.org/devdocs/release/1.20.0-notes.html#using-the-aliases-of-builtin-types-like-np-int-is-deprecated

This worked with catboost 1.1.1 with numpy 1.22.3.

@saiwing-yeung
Copy link
Author

Also works with catboost 1.2 and numpy 1.23.5.

@saiwing-yeung
Copy link
Author

Thanks!

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