Skip to content

ENH: Add dtype of categories to repr of CategoricalDtype #52202

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

Merged
merged 5 commits into from
Mar 29, 2023

Conversation

phofl
Copy link
Member

@phofl phofl commented Mar 25, 2023

@phofl phofl added the Categorical Categorical Data Type label Mar 25, 2023
@mroeschke
Copy link
Member

=================================== FAILURES ===================================
__ [doctest] pandas.core.dtypes.dtypes.CategoricalDtype._from_values_or_dtype __
246             If ``CategoricalDtype``, cannot be used together with
247             `categories` or `ordered`.
248 
249         Returns
250         -------
251         CategoricalDtype
252 
253         Examples
254         --------
255         >>> pd.CategoricalDtype._from_values_or_dtype()
Expected:
    CategoricalDtype(categories=None, ordered=None)
Got:
    CategoricalDtype(categories=None, ordered=None, categories_dtype=None)

/home/runner/work/pandas/pandas/pandas/core/dtypes/dtypes.py:255: DocTestFailure
___ [doctest] pandas.io.json._table_schema.convert_json_field_to_pandas_type ___
167     ------
168     ValueError
169         If the type of the provided field is unknown or currently unsupported
170 
171     Examples
172     --------
173     >>> convert_json_field_to_pandas_type({"name": "an_int", "type": "integer"})
174     'int64'
175 
176     >>> convert_json_field_to_pandas_type(
Expected:
    CategoricalDtype(categories=['a', 'b', 'c'], ordered=True)
Got:
    CategoricalDtype(categories=['a', 'b', 'c'], ordered=True, categories_dtype=object)

@@ -429,13 +429,19 @@ def __eq__(self, other: Any) -> bool:
def __repr__(self) -> str_type:
if self.categories is None:
data = "None"
dtype = "None"
Copy link
Member

Choose a reason for hiding this comment

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

Do we have a test that hits this branch?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, can't recall which one exactly but got a failure before I added this

phofl and others added 3 commits March 29, 2023 10:15
Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com>
@mroeschke mroeschke added this to the 2.1 milestone Mar 29, 2023
@mroeschke mroeschke merged commit 0cdaa71 into pandas-dev:main Mar 29, 2023
@mroeschke
Copy link
Member

Thanks @phofl

@phofl phofl deleted the 52179 branch March 30, 2023 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Categorical Categorical Data Type
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ENH: CategoricalDtype __repr__ should show dtype of categories
2 participants