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

Typehint for some core API. #7348

Merged
merged 1 commit into from Oct 28, 2021
Merged

Conversation

trivialfis
Copy link
Member

@trivialfis trivialfis commented Oct 20, 2021

Cross-validation and low-level primitives are not handled yet.

To have full coverage we need #7242 and a cleanly implemented of cv.

  • Use Sequence instead of List for public functions/methods.
  • Add type hint for some core public functions.

@codecov-commenter
Copy link

codecov-commenter commented Oct 20, 2021

Codecov Report

Merging #7348 (dfd060e) into master (f53da41) will increase coverage by 0.08%.
The diff coverage is 99.30%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #7348      +/-   ##
==========================================
+ Coverage   83.70%   83.79%   +0.08%     
==========================================
  Files          13       13              
  Lines        3890     3899       +9     
==========================================
+ Hits         3256     3267      +11     
+ Misses        634      632       -2     
Impacted Files Coverage Δ
python-package/xgboost/sklearn.py 91.14% <ø> (ø)
python-package/xgboost/core.py 84.75% <98.52%> (+0.19%) ⬆️
python-package/xgboost/callback.py 97.76% <100.00%> (+0.05%) ⬆️
python-package/xgboost/tracker.py 86.55% <100.00%> (ø)
python-package/xgboost/training.py 95.02% <100.00%> (+0.05%) ⬆️
python-package/xgboost/dask.py 82.79% <0.00%> (+0.04%) ⬆️

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 f53da41...dfd060e. Read the comment docs.

@feature_names.setter
def feature_names(self, features: Optional[List[str]]) -> None:
self._set_feature_info(features, "feature_name")
@property
Copy link
Member Author

Choose a reason for hiding this comment

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

Mypy has issue with separated property getter/setter.

@@ -2356,7 +2367,7 @@ def trees_to_dataframe(self, fmap=''): # pylint: disable=too-many-statements
node_ids = []
fids = []
splits = []
categories = []
categories: List[Optional[float]] = []
Copy link
Member Author

Choose a reason for hiding this comment

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

Mostly for the Optional type that mypy can not infer.

@@ -941,40 +939,26 @@ def apply(
iteration_range=iteration_range
)

def evals_result(self) -> TrainingCallback.EvalsLog:
def evals_result(self) -> Dict[str, Dict[str, List[float]]]:
Copy link
Member Author

Choose a reason for hiding this comment

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

EvalsLog contains CV result, while Sklearn interface uses only train.

@@ -1354,48 +1338,6 @@ def predict_proba(
getattr(self, "n_classes_", None), class_probs, np.vstack
)

def evals_result(self) -> TrainingCallback.EvalsLog:
Copy link
Member Author

Choose a reason for hiding this comment

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

Removed as this function can be called by inheritance. We just have to unify the document.

@@ -917,7 +915,7 @@ def apply(
Input features matrix.

iteration_range :
See :py:meth:`xgboost.XGBRegressor.predict`.
See :py:meth:`predict`.
Copy link
Member Author

Choose a reason for hiding this comment

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

This way sphinx can automatically choose the correct method which belongs to current class.

# Not improved
self.stopping_history[name][metric].append(score)
self.stopping_history[name][metric].append(score) # type: ignore
Copy link
Member Author

Choose a reason for hiding this comment

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

The type is Union[List[float], List[Tuple[float, float]], later is for cv function. A bit too tedious to cast it all the time.

@@ -660,10 +661,7 @@ def _configure_fit(

def _set_evaluation_result(self, evals_result: TrainingCallback.EvalsLog) -> None:
if evals_result:
for val in evals_result.items():
Copy link
Member Author

Choose a reason for hiding this comment

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

Not needed, the very complicated transformation is just getting the same result as input.

Cross validation and low level primitives are not handled yet.

Fix.

Callback API.

Fix build doc.

Fix doc.

Add allreduce type.

More restricted type.

Convert it first.

Get the score working.

lint.

Cleanup.

Cleanup the document.

Use sequence instead of list or tuple.

lint.

Use sequence.
@trivialfis trivialfis merged commit c676948 into dmlc:master Oct 28, 2021
@trivialfis trivialfis deleted the core-typehint branch October 28, 2021 12:47
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.

None yet

3 participants