# Buggy code
def _fit(self, X, handle_unknown="error"):
    X = self._check_X(X)

    n_samples, n_features = X.shape

    if self._categories != "auto":
        if X.dtype != object:
            for cats in self._categories:
                if not np.all(np.sort(cats) == np.array(cats)):
                    raise ValueError(
                        "Unsorted categories are not supported for numerical categories"
                    )
        if len(self._categories) != n_features:
            raise ValueError(
                "Shape mismatch: if n_values is an array,"
                " it has to be of shape (n_features,)."
            )

    self.categories_ = []

    for i in range(n_features):
        Xi = X[:, i]
        if self._categories == "auto":
            cats = _encode(Xi)
        else:
            cats = np.array(self._categories[i], dtype=X.dtype)
            if self.handle_unknown == "error":
                diff = _encode_check_unknown(Xi, cats)
                if diff:
                    msg = (
                        "Found unknown categories {0} in column {1} during fit".format(
                            diff, i
                        )
                    )
                    raise ValueError(msg)
        self.categories_.append(cats)


# Traceback (AttributeError)
/usr/local/lib/python3.6/dist-packages/sklearn/externals/joblib/externals/cloudpickle/cloudpickle.py:47: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
import imp
Traceback (most recent call last):
File "bug.py", line 9, in <module>
enc.fit(a)
File "/usr/local/lib/python3.6/dist-packages/sklearn/preprocessing/_encoders.py", line 774, in fit
self._fit(X)
File "/usr/local/lib/python3.6/dist-packages/sklearn/preprocessing/_encoders.py", line 85, in _fit
if self.handle_unknown == 'error':
AttributeError: 'OrdinalEncoder' object has no attribute 'handle_unknown'

# Fixed code
def _fit(self, X, handle_unknown="error"):
    X = self._check_X(X)

    n_samples, n_features = X.shape

    if self._categories != "auto":
        if X.dtype != object:
            for cats in self._categories:
                if not np.all(np.sort(cats) == np.array(cats)):
                    raise ValueError(
                        "Unsorted categories are not supported for numerical categories"
                    )
        if len(self._categories) != n_features:
            raise ValueError(
                "Shape mismatch: if n_values is an array,"
                " it has to be of shape (n_features,)."
            )

    self.categories_ = []

    for i in range(n_features):
        Xi = X[:, i]
        if self._categories == "auto":
            cats = _encode(Xi)
        else:
            cats = np.array(self._categories[i], dtype=X.dtype)
            if handle_unknown == "error":
                diff = _encode_check_unknown(Xi, cats)
                if diff:
                    msg = (
                        "Found unknown categories {0} in column {1} during fit".format(
                            diff, i
                        )
                    )
                    raise ValueError(msg)
        self.categories_.append(cats)