- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 19.2k
Fix: DataFrame created with tzinfo cannot use to_dict(orient="records) #18416
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
Conversation
bcdda73    to
    1af1f6c      
    Compare
  
            
          
                doc/source/whatsnew/v0.22.0.txt
              
                Outdated
          
        
      | ^^^^^^^^^^ | ||
|  | ||
| - | ||
| - Bug in :func:`DataFrame.to_dict` where columns of datetimez where not arrays when used with ``orient='records'`` (:issue:`18372`) | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you make this a bit more clear
| assert xp == rs | ||
|  | ||
| def test_frame_to_dict_tz(self): | ||
| data = [(datetime(2017, 11, 18, 21, 53, 0, 219225, tzinfo=pytz.utc),), | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add the issue number as a comment.
this test goes in pandas/tests/frames/test_convert_to.py
| (datetime(2017, 11, 18, 22, 6, 30, 61810, tzinfo=pytz.utc,),)] | ||
| df = DataFrame(list(data), columns=["datetime", ]) | ||
|  | ||
| rec = df.to_dict(orient='records') | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
result =
| df = DataFrame(list(data), columns=["datetime", ]) | ||
|  | ||
| rec = df.to_dict(orient='records') | ||
| t1 = Timestamp('2017-11-18 21:53:00.219225+0000', tz=pytz.utc) | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
construct the dict and compare, call it expected
| return [into_c((k, _maybe_box_datetimelike(v)) | ||
| for k, v in zip(self.columns, row)) | ||
| for k, v in zip(self.columns, np.atleast_1d(row))) | ||
| for row in self.values] | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't the np.atleast_2d be around self.values?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it fails then. In that case only one of the results will be returned, effectively flattening the array.
1af1f6c    to
    00dab99      
    Compare
  
    There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor comments, ping when pushed / green.
| assert isinstance(result[0]['a'], (int, long)) | ||
|  | ||
| def test_frame_to_dict_tz(self): | ||
| data = [(datetime(2017, 11, 18, 21, 53, 0, 219225, tzinfo=pytz.utc),), | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add the issue number here as a comment.
        
          
                doc/source/whatsnew/v0.22.0.txt
              
                Outdated
          
        
      | ^^^^^^^^^^ | ||
|  | ||
| - | ||
| - Bug in :func:`DataFrame.to_dict` where columns of datetimez were not converted to required arrays when used with ``orient='records'``, raising``TypeError` (:issue:`18372`) | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
say columns of datetime that are tz-aware, were not ......
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can move this to 0.21.1
        
          
                doc/source/whatsnew/v0.22.0.txt
              
                Outdated
          
        
      | ^^^^^^^^^^ | ||
|  | ||
| - | ||
| - Bug in :func:`DataFrame.to_dict` where columns of datetimez were not converted to required arrays when used with ``orient='records'``, raising``TypeError` (:issue:`18372`) | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can move this to 0.21.1
| Codecov Report
 @@            Coverage Diff             @@
##           master   #18416      +/-   ##
==========================================
- Coverage   91.35%   91.34%   -0.02%     
==========================================
  Files         163      163              
  Lines       49691    49691              
==========================================
- Hits        45397    45388       -9     
- Misses       4294     4303       +9
 
 Continue to review full report at Codecov. 
 | 
00dab99    to
    4a3d28f      
    Compare
  
    | Hello @bolkedebruin! Thanks for updating the PR. Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated on November 23, 2017 at 13:10 Hours UTC | 
…cords") Columns with datetimez are not returning arrays. Closes pandas-dev#18372
4a3d28f    to
    e861d08      
    Compare
  
    | thanks @bolkedebruin | 
…cords") (pandas-dev#18416) Closes pandas-dev#18372 (cherry picked from commit 4e09480)
Columns with datetimez are not returning arrays.
Closes #18372
git diff upstream/master -u -- "*.py" | flake8 --diff