Skip to content

spaces converted to todays date with to_datetime and read_csv date parse #6428

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

Closed
hayd opened this issue Feb 21, 2014 · 0 comments · Fixed by #14862
Closed

spaces converted to todays date with to_datetime and read_csv date parse #6428

hayd opened this issue Feb 21, 2014 · 0 comments · Fixed by #14862
Labels
Bug Datetime Datetime data dtype IO CSV read_csv, to_csv Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Milestone

Comments

@hayd
Copy link
Contributor

hayd commented Feb 21, 2014

In [265]: s = pd.Series(['10/18/2006', '10/18/2008', ' '])

In [266]: pd.to_datetime(s)
Out[266]:
0   2006-10-18
1   2008-10-18
2   2014-02-20
dtype: datetime64[ns]

In [268]: pd.to_datetime(s, errors='raise')
Out[268]:
0   2006-10-18
1   2008-10-18
2   2014-02-20
dtype: datetime64[ns]

Note: Can use pd.to_datetime(s, format='%m/%d/%Y', coerce=True).

This also seems to be the case when reading from csv.

csv = """case,opdate
7,10/18/2006
7,10/18/2008
621, """

In [282]: pd.read_csv(StringIO(csv), parse_dates=['opdate'])
Out[282]:
   case     opdate
0     7 2006-10-18
1     7 2008-10-18
2   621 2014-02-20

[3 rows x 2 columns]

See this SO question http://stackoverflow.com/questions/21922978/safest-pandas-read-csv-with-missing-dates/21924845#21924845

Maybe stems from:

In [284]: pd.datetools.parse(' ')
Out[284]: datetime.datetime(2014, 2, 20, 0, 0)
@jreback jreback added this to the 0.15.0 milestone Feb 25, 2014
@jreback jreback modified the milestones: 0.16.0, Next Major Release Mar 3, 2015
mroeschke added a commit to mroeschke/pandas that referenced this issue Dec 12, 2016
mroeschke added a commit to mroeschke/pandas that referenced this issue Dec 14, 2016
Add doc explaining parse_date limitation
@jorisvandenbossche jorisvandenbossche modified the milestones: 0.20.0, Next Major Release Dec 14, 2016
jorisvandenbossche pushed a commit that referenced this issue Dec 14, 2016
+ Add doc explaining parse_date limitation
ischurov pushed a commit to ischurov/pandas that referenced this issue Dec 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Datetime Datetime data dtype IO CSV read_csv, to_csv Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants