You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2019/01/07 21:44:37 UTC

[GitHub] timifasubaa closed pull request #5369: [WIP] Remove unneeded form fields from csv import

timifasubaa closed pull request #5369: [WIP] Remove unneeded form fields from csv import
URL: https://github.com/apache/incubator-superset/pull/5369
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/superset/db_engine_specs.py b/superset/db_engine_specs.py
index 0f10d82a9d..ffb057bb28 100644
--- a/superset/db_engine_specs.py
+++ b/superset/db_engine_specs.py
@@ -169,16 +169,13 @@ def _allowed_file(filename):
             raise Exception('Invalid file type selected')
         kwargs = {
             'filepath_or_buffer': filename,
-            'sep': form.sep.data,
-            'header': form.header.data if form.header.data else 0,
+            'header': 0,
             'index_col': form.index_col.data,
-            'mangle_dupe_cols': form.mangle_dupe_cols.data,
-            'skipinitialspace': form.skipinitialspace.data,
-            'skiprows': form.skiprows.data,
-            'nrows': form.nrows.data,
-            'skip_blank_lines': form.skip_blank_lines.data,
+            'mangle_dupe_cols': False,
+            'skipinitialspace': True,
+            'skip_blank_lines': True,
             'parse_dates': form.parse_dates.data,
-            'infer_datetime_format': form.infer_datetime_format.data,
+            'infer_datetime_format': True,
             'chunksize': 10000,
         }
         df = BaseEngineSpec.csv_to_df(**kwargs)
@@ -189,9 +186,7 @@ def _allowed_file(filename):
             'name': form.name.data,
             'con': create_engine(form.con.data.sqlalchemy_uri_decrypted, echo=False),
             'schema': form.schema.data,
-            'if_exists': form.if_exists.data,
-            'index': form.index.data,
-            'index_label': form.index_label.data,
+            'if_exists': 'fail',
             'chunksize': 10000,
         }
 
diff --git a/superset/forms.py b/superset/forms.py
index 0537ded3e4..c7ecfd22c3 100644
--- a/superset/forms.py
+++ b/superset/forms.py
@@ -57,101 +57,31 @@ def all_db_items():
         description=_('Name of table to be created from csv data.'),
         validators=[DataRequired()],
         widget=BS3TextFieldWidget())
-    csv_file = FileField(
-        _('CSV File'),
-        description=_('Select a CSV file to be uploaded to a database.'),
-        validators=[
-            FileRequired(), FileAllowed(['csv'], _('CSV Files Only!'))])
-    con = QuerySelectField(
-        _('Database'),
-        query_factory=all_db_items,
-        get_pk=lambda a: a.id, get_label=lambda a: a.database_name)
-    sep = StringField(
-        _('Delimiter'),
-        description=_('Delimiter used by CSV file (for whitespace use \s+).'),
-        validators=[DataRequired()],
-        widget=BS3TextFieldWidget())
-    if_exists = SelectField(
-        _('Table Exists'),
-        description=_(
-            'If table exists do one of the following: '
-            'Fail (do nothing), Replace (drop and recreate table) '
-            'or Append (insert data).'),
-        choices=[
-            ('fail', _('Fail')), ('replace', _('Replace')),
-            ('append', _('Append'))],
-        validators=[DataRequired()])
     schema = StringField(
         _('Schema'),
         description=_('Specify a schema (if database flavour supports this).'),
         validators=[Optional()],
         widget=BS3TextFieldWidget(),
         filters=[lambda x: x or None])
-    header = IntegerField(
-        _('Header Row'),
-        description=_(
-            'Row containing the headers to use as '
-            'column names (0 is first line of data). '
-            'Leave empty if there is no header row.'),
-        validators=[Optional()],
-        widget=BS3TextFieldWidget(),
-        filters=[lambda x: x or None])
+    con = QuerySelectField(
+        _('Database'),
+        query_factory=all_db_items,
+        get_pk=lambda a: a.id, get_label=lambda a: a.database_name)
+    csv_file = FileField(
+        _('CSV File'),
+        description=_('Select a CSV file to be uploaded to a database.'),
+        validators=[
+            FileRequired(), FileAllowed(['csv'], _('CSV Files Only!'))])
     index_col = IntegerField(
         _('Index Column'),
         description=_(
-            'Column to use as the row labels of the '
-            'dataframe. Leave empty if no index column.'),
+            'Zero indexed position of column to use for index.'
+            'If a sequence is given, a MultiIndex is used.',
         validators=[Optional(), NumberRange(0, 1E+20)],
         widget=BS3TextFieldWidget(),
         filters=[lambda x: x or None])
-    mangle_dupe_cols = BooleanField(
-        _('Mangle Duplicate Columns'),
-        description=_('Specify duplicate columns as "X.0, X.1".'))
-    skipinitialspace = BooleanField(
-        _('Skip Initial Space'),
-        description=_('Skip spaces after delimiter.'))
-    skiprows = IntegerField(
-        _('Skip Rows'),
-        description=_('Number of rows to skip at start of file.'),
-        validators=[Optional(), NumberRange(0, 1E+20)],
-        widget=BS3TextFieldWidget(),
-        filters=[lambda x: x or None])
-    nrows = IntegerField(
-        _('Rows to Read'),
-        description=_('Number of rows of file to read.'),
-        validators=[Optional(), NumberRange(0, 1E+20)],
-        widget=BS3TextFieldWidget(),
-        filters=[lambda x: x or None])
-    skip_blank_lines = BooleanField(
-        _('Skip Blank Lines'),
-        description=_(
-            'Skip blank lines rather than interpreting them '
-            'as NaN values.'))
-    parse_dates = CommaSeparatedListField(
-        _('Parse Dates'),
-        description=_(
-            'A comma separated list of columns that should be '
-            'parsed as dates.'),
-        filters=[filter_not_empty_values])
     infer_datetime_format = BooleanField(
         _('Infer Datetime Format'),
         description=_(
             'Use Pandas to interpret the datetime format '
             'automatically.'))
-    decimal = StringField(
-        _('Decimal Character'),
-        description=_('Character to interpret as decimal point.'),
-        validators=[Optional()],
-        widget=BS3TextFieldWidget(),
-        filters=[lambda x: x or '.'])
-    index = BooleanField(
-        _('Dataframe Index'),
-        description=_('Write dataframe index as a column.'))
-    index_label = StringField(
-        _('Column Label(s)'),
-        description=_(
-            'Column label for index column(s). If None is given '
-            'and Dataframe Index is True, Index Names are used.'),
-        validators=[Optional()],
-        widget=BS3TextFieldWidget(),
-        filters=[lambda x: x or None])
diff --git a/superset/views/core.py b/superset/views/core.py
index 0e51eac044..dd03e1e020 100755
--- a/superset/views/core.py
+++ b/superset/views/core.py
@@ -340,13 +340,7 @@ class CsvToDatabaseView(SimpleFormView):
 
     def form_get(self, form):
         form.sep.data = ','
-        form.header.data = 0
         form.mangle_dupe_cols.data = True
-        form.skipinitialspace.data = False
-        form.skip_blank_lines.data = True
-        form.infer_datetime_format.data = True
-        form.decimal.data = '.'
-        form.if_exists.data = 'append'
 
     def form_post(self, form):
         csv_file = form.csv_file.data


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org