question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: data type "category" not understood

See original GitHub issue

Hi, Trying to reproduce example. It is throwing following error for this code

# Main dataset to show datasloth capabilities
titanic = sns.load_dataset('titanic')
titanic.head()
titanic.sloth.description = 'Verbose description of the table'
sloth.query("Number of men which survived the titanic", show_query=True)
Output exceeds the [size limit](command:workbench.action.openSettings?[). Open the full output data [in a text editor](command:workbench.action.openLargeOutput?5c05cb7d-1b4d-48ee-8e94-e8afceb177c6)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-12-b1e190aa764c> in <module>
      5 titanic.head()
      6 titanic.sloth.description = 'Verbose description of the table'
----> 7 sloth.query("Number of men which survived the titanic", show_query=True)

~/.local/lib/python3.6/site-packages/datasloth/__init__.py in query(self, query, env, show_query)
    118         env = env or get_outer_frame_variables()
    119         query = query[0].lower() + query[1:]
--> 120         prompt = self.dataframes_summary(env)
    121         if not prompt:
    122             print('No dataframes found')

~/.local/lib/python3.6/site-packages/datasloth/__init__.py in dataframes_summary(env, ignore)
    102                 summary_lines += [
    103                     f"\n\nTable name: {name}",
--> 104                     value.sloth.description
    105                 ]
    106                 table_count += 1

~/.local/lib/python3.6/site-packages/datasloth/__init__.py in description(self)
     27     @property
     28     def description(self) -> str:
---> 29         return self._description.format(COLUMNS_SUMMARY=self.columns_summary())
...
--> 200     if is_string_dtype(col) or col.dtype == 'category':
    201         unique = col.unique().tolist()
    202         summary = 'unique values: ' + ', '.join(map(str, unique[:30]))

TypeError: data type "category" not understood

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ibestvinacommented, Sep 6, 2022

Hey, great! Yes, it loads all dataframes in environment, apart from those which names start with an underscore. So if you want to “hide” something from it, you can name the variable that way (e.g. _df).

Another way you can do it is to give datasloth a custom environment like this:

custom_env = {
'sales': sales,
'prices': prices
}
datasloth.query('Some query text', env=custom_env)

Sadly, it’s a bit ugly for now since I didn’t have much time to work on these custom envs. Make sure in that dict, the “keys” are the same as the variable names you use - you cannot pick a different name here. I have to do it like this since it’s impossible for datasloth to know what names you’ve used in your scope for this dataframes otherwise.

0reactions
ibestvinacommented, Sep 6, 2022

Very glad to hear you’re enjoying it! Just keep the questions coming if you find any other issue 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: data type 'category' not understood pandas ...
I have a dataframe df , with dtypes: category(16), float32(65), int32(41) . I want to perform some analysis on the categorical column. but...
Read more >
Keep getting "data type 'category' not understood"? - Reddit
Hi, So I'm trying to convert my categorical data into numbers and use it for a correlation matrix. However, when I run this:...
Read more >
Categorical Data — pandas 0.17.0 documentation - PyData |
Categoricals are a pandas data type, which correspond to categorical variables in ... TypeError: data type "category" not understood In [172]: dtype =...
Read more >
astype errors with Categorical #16697 - pandas-dev ... - GitHub
dtypes[colname] == 'category' evaluates as True for categorical columns and raises TypeError: data type "category" not understood for np.float64 ...
Read more >
5.12 Gotchas — Pandas Doc - GitHub Pages
TypeError : data type "category" not understood In [8]: dtype = pd. ... Series of type category should not work as Categoricals are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found