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

type_check_date function doesn't work #53

Closed
ea-rus opened this issue Oct 4, 2023 · 3 comments
Closed

type_check_date function doesn't work #53

ea-rus opened this issue Oct 4, 2023 · 3 comments
Assignees
Labels
wontfix This will not be worked on

Comments

@ea-rus
Copy link
Contributor

ea-rus commented Oct 4, 2023

Steps to replicate

df = pd.DataFrame([{'month': '2017-07-01'}, {'month': '2017-08-01'}, {'month': '2017-09-01'}])

import type_infer
type_infer.infer.type_check_date(df['month'])

Raises:

  File "/work/mindsdb/mindsdb_main/venv/lib/python3.10/site-packages/type_infer/infer.py", line 135, in type_check_date
    if dt.hour == 0 and dt.minute == 0 and dt.second == 0 and len(str(element)) <= 16:
  File "/work/mindsdb/mindsdb_main/venv/lib/python3.10/site-packages/pandas/core/generic.py", line 5989, in __getattr__
    return object.__getattribute__(self, name)
AttributeError: 'Series' object has no attribute 'hour'
@paxcema
Copy link
Contributor

paxcema commented Oct 4, 2023

Related: mindsdb#7419. Once this is solved, we should change the linked code so that it uses type_infer instead.

@pedrofluxa
Copy link
Contributor

pedrofluxa commented Oct 4, 2023

The function type_check_date is intended to work with a single element, that is, non iterable objects.

This issue arises when calling the function with a pandas.Series (which is iterable), which is a perfectly valid use case for pandas.to_datetime() but makes the function crash as pandas.to_datetime() returns a pandas.Series when called with a pandas.Series as argument. This is in opposition to the intended functionality, which is to be called with a single element as argument.

The following code works as intended

import pandas as pd
import type_infer

df = pd.DataFrame([{'month': '2017-07-01'}, {'month': '2017-08-01'}, {'month': '2017-09-01'}])
for element in df['month']:
    print(type_infer.infer.type_check_date(element))

which outputs (in ipython)

datetime
datetime
datetime

Shall the user require support to check the type of a pandas.Series using this function, please let me know :)

@paxcema paxcema added the wontfix This will not be worked on label Oct 4, 2023
@paxcema
Copy link
Contributor

paxcema commented Oct 4, 2023

Closing as won't fix, not an actual issue.

@paxcema paxcema closed this as completed Oct 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants