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

chat with 12h clock not working properly #40

Closed
lucasrodes opened this issue May 2, 2020 · 1 comment · Fixed by #49
Closed

chat with 12h clock not working properly #40

lucasrodes opened this issue May 2, 2020 · 1 comment · Fixed by #49
Assignees
Labels
Projects

Comments

@lucasrodes
Copy link
Owner

Given a chat with the following format:

2015-08-22, 12:15 PM - X: bla bla
2015-08-22, 12:15 PM - Y: bla
2015-08-22, 12:16 PM - Y: blabla
2015-08-22, 12:17 PM - X: bla

Both with auto_header option

>>> from whatstk import WhatsAppChat
>>> chat = WhatsAppChat.from_txt('example.txt')

and manually setting hformat

>>> from whatstk import WhatsAppChat
>>> chat = WhatsAppChat.from_txt('example.txt', hformat='%y-%m-%d, %P:%M - %name:')

a KeyError exception is raised:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
   2656             try:
-> 2657                 return self._engine.get_loc(key)
   2658             except KeyError:

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: 'date'

During handling of the above exception, another exception occurred:

KeyError                                  Traceback (most recent call last)
<ipython-input-4-5e2de28f6c26> in <module>
----> 1 chat = WhatsAppChat.from_txt(filename)

~/whatstk/whatstk/objects.py in from_txt(cls, filename, auto_header, hformat, encoding)
     44         hformat.replace('[', '\[').replace(']', '\]')
     45         # Prepare DataFrame
---> 46         df = cls._prepare_df(text, hformat)
     47 
     48         return cls(df)

~/whatstk/whatstk/objects.py in _prepare_df(text, hformat)
     79 
     80         # Parse chat to DataFrame
---> 81         df = parse_chat(text, r)
     82 
     83         # get rid of wp warning messages

~/whatstk/whatstk/utils/parser.py in parse_chat(text, regex)
     51         line_dict = _parse_line(text, headers, i)
     52         result.append(line_dict)
---> 53     df_chat = pd.DataFrame.from_records(result, index='date')
     54     return df_chat[['username', 'message']]
     55 

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pandas/core/frame.py in from_records(cls, data, index, exclude, columns, coerce_float, nrows)
   1527             if (isinstance(index, compat.string_types) or
   1528                     not hasattr(index, "__iter__")):
-> 1529                 i = columns.get_loc(index)
   1530                 exclude.add(index)
   1531                 if len(arrays) > 0:

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
   2657                 return self._engine.get_loc(key)
   2658             except KeyError:
-> 2659                 return self._engine.get_loc(self._maybe_cast_indexer(key))
   2660         indexer = self.get_indexer([key], method=method, tolerance=tolerance)
   2661         if indexer.ndim > 1 or indexer.size > 1:

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: 'date'
@lucasrodes lucasrodes added the bug label May 2, 2020
@lucasrodes lucasrodes added this to BACKLOG in Road Map May 2, 2020
lucasrodes pushed a commit that referenced this issue May 4, 2020
@albertaparicio albertaparicio moved this from BACKLOG to TO DO in Road Map May 5, 2020
@lucasrodes lucasrodes self-assigned this May 5, 2020
@lucasrodes
Copy link
Owner Author

lucasrodes commented May 5, 2020

Manually setting format works, should be as:

>>> from whatstk import WhatsAppChat
>>> chat = WhatsAppChat.from_txt('example.txt', hformat='%y-%m-%d, %H:%M %P - %name:')

Now working on making auto_header option available for 12h clock.

This was referenced May 6, 2020
@lucasrodes lucasrodes moved this from TO DO to DONE in Road Map May 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

Successfully merging a pull request may close this issue.

1 participant