[jira] [Created] (FLINK-19894) Use iloc for positional slicing instead of direct slicing in from_pandas

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[jira] [Created] (FLINK-19894) Use iloc for positional slicing instead of direct slicing in from_pandas

Shang Yuanchun (Jira)
Huang Xingbo created FLINK-19894:
------------------------------------

             Summary: Use iloc for positional slicing instead of direct slicing in from_pandas
                 Key: FLINK-19894
                 URL: https://issues.apache.org/jira/browse/FLINK-19894
             Project: Flink
          Issue Type: Bug
          Components: API / Python
    Affects Versions: 1.11.2, 1.12.0
            Reporter: Huang Xingbo


When you use floats are index of pandas, it produces a wrong results:

 
{code:java}
>>> import pandas as pd
>>> t_env.from_pandas(pd.DataFrame({'a': [1, 2, 3]}, index=[2., 3., 4.])).to_pandas()
   a
0  1
1  2
{code}
 

This is because direct slicing uses the value as index when the index contains floats:

 
{code:java}
>>> pd.DataFrame({'a': [1,2,3]}, index=[2., 3., 4.])[2:]
     a
2.0  1
3.0  2
4.0  3
>>> pd.DataFrame({'a': [1,2,3]}, index=[2., 3., 4.]).iloc[2:]
     a
4.0  3
>>> pd.DataFrame({'a': [1,2,3]}, index=[2, 3, 4])[2:]
   a
4  3{code}
 



--
This message was sent by Atlassian Jira
(v8.3.4#803005)